Re: Quantities are Singletons?
Matthias Radestock <[email protected]> Thu, 08 Jul 2004 09:19:13 +0100
| Newsgroups | gmane.comp.java.sisc.devel |
|---|---|
| Message-ID | <[email protected]> |
Isaac Morland wrote:
> In Quantity.java (SISC 1.8.8), we have:
>
> public Value singletonValue() {
> return this;
> }
>
> And in the interpreter I get:
>
> #;> (= 5 5)
> #t
> #;> (eq? 5 5)
> #f
> #;> (eqv? 5 5)
> #t
> #;>
>
> So it would appear that quantities don't truly follow the contract for
> Singleton. Perhaps they were meant to be true singletons but that feature
> has never been implemented? A quick perusal of R5RS 6.1 suggests that
> this behaviour is legal R5RS so maybe the fix is simply to remove the
> "implements Singleton" from the top of Quantity.java.
The term singleton might be somewhat misleading. The main purpose of the
interface is to tell the Serializer that it doesn't need to care about
object identities when serializing the object. Quantities meet that
condition.
> Note however the following:
>
> #;> (equal? 5 5.0)
> #t
> #;> (eqv? 5 5.0)
> #f
> #;>
>
> Is the result for equal? not a bug? R5RS defines equal? as recursively
> processing pairs, vectors, and string, using eqv? to compare things like
> numbers.
That looks like a bug. You are right that equal? for numbers is supposed
to be the same as eqv?. According to the standard, eqv? on numbers is #f
if they are of different exactness, and the result of = otherwise. I
believe SISCs numeric equal? is the same as = and hence misses the first
condition.
Matthias.
-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
digital self defense, top technical experts, no vendor pitches,
unmatched networking opportunities. Visit www.blackhat.com