Identity vs equality (was Re: [Newbies] Assignment)

nicolas cellier ncellier at ifrance.com
Mon Aug 13 12:00:56 UTC 2007


Alexander Lazarević a écrit :
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
>> Err ... so what is your point? Are you claiming that 1 should not equal
>> 1.0?
> 
> ? No.
> 
>> Or that there is a substantial difference between 'foo' and #foo
>> and that they shouldn't compare equal?
> 
> Yes.
> 
>> Or that 'foo' = #foo but #foo ~= 'foo'?
> 
> No.
> 
>> *My* only point was that comparison should be symmetrical, as
>> excemplified by the fact that iff 1 = 1.0 then 1.0 = 1.
> 
> Ah ... crossreading the thread I lost the symmetry aspect. Sorry for the
> confusion.
> 
> 
> Alex
> -----BEGIN PGP SIGNATURE-----
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
> 
> iD8DBQFGwCliYiF2wSTEZ9gRAntxAKCLoQrj6rcQ45JgJH8TknMT7EwNagCgzMNz
> i0FM4fPnAwSHa9dsAJTtmuo=
> =NBj0
> -----END PGP SIGNATURE-----
> 
> 

I Just want to add that Float are rather a subset of Q rather than R. 
They are only fractions with denominator being a power of two.

And yes, we all expect = to behave symmetrically, whatever our 
mathematical background, though it strictly does not have to.

This is one of my pets, and i'm glad to remind everybody that once 
symmetry is cured, = is still not an equivalence relationship, because 
transitivity is often broken.

a := 2 raisedTo: 80.
b := a asDouble.
c := a+1.
self should: [(a = b) & (b = c) ==> (a = c)].

Andres Valloud argued that Float should never equal Integer because they 
are inexact.

I found this a little extremist because 1.0 is still exact. I proposed 
instead to answer true only if conversion is exact.

The problem with IEEE is that inexact flag is not bound to the float 
itself but somewhere in a processor register... So we forget this 
information as soon as we store the result. Anyway, most Float will be 
inexact. So both acceptions are acceptable.

Scheme authorizes the above two implementations.
In Squeak, we have all the elements for making a decision, 
implementation are ready in mantis, the thread have been over-discussed, 
we just need an authority to choose, or vote if some prefer democracy. 
Instead of that, we take no decision at all... Sure, the bug is minor, 
but it's always better to avoid bugs in foundations.

By the way, not only Float are broken, try:

a := (3 to: 2).
b := #().
c := (2 to: 1).
self should: [(a = b) & (b = c) ==> (a = c)].

This also is on mantis...

And don't play with set with these beasts, when they equal, their hash 
rarely do so (has a solution in mantis too).

Nicolas




More information about the Squeak-dev mailing list