Hi guys, I have another noob question :) Why Association>>#= is not = anAssociation ^self == anAssociation or: [super = anAssociation and: [value = anAssociation value]] Because I can have strange behavior like association := #foo -> Float nan. {association} includes: association answer false :S Thanks, Ben
I don't really know the answer, but it is not about the implementation in Association. It is reasonable for associations to be equal if both their key & value are equal. The problem as you have seen is Float nan does not compare using #=. Float nan = Float nan --> false I don't the details but perhaps the clue is in the implementation of isNaN isNaN "simple, byte-order independent test for Not-a-Number" ^ self ~= self so something like this seems a better test association := #foo -> Float nan. {association} anySatisfy: [:each | each value isNaN] cheers, Mike On Mon, Nov 15, 2010 at 3:06 PM, Benjamin <benjamin.vanryseghem.pharo@gmail.com> wrote:
Hi guys,
I have another noob question :)
Why Association>>#= is not
= anAssociation
    ^self == anAssociation or: [super = anAssociation and: [value = anAssociation value]]
Because I can have strange behavior like
association := #foo -> Float nan.
{association} includes: association
answer false
:S
Thanks,
Ben
_______________________________________________ Pharo-users mailing list Pharo-users@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users
On Nov 16, 2010, at 9:20 AM, Michael Roberts wrote:
I don't really know the answer, but it is not about the implementation in Association. It is reasonable for associations to be equal if both their key & value are equal. The problem as you have seen is Float nan does not compare using #=.
Float nan = Float nan --> false
I don't the details but perhaps the clue is in the implementation of isNaN
isNaN "simple, byte-order independent test for Not-a-Number"
^ self ~= self
so something like this seems a better test
association := #foo -> Float nan. {association} anySatisfy: [:each | each value isNaN]
cheers, Mike
Thank you, it's a good clue :) It's not really cool to have to add special code to test NaN, but if it's the only way ... Ben
On Tue, Nov 16, 2010 at 3:17 AM, Benjamin <benjamin.vanryseghem.pharo@gmail.com> wrote:
On Nov 16, 2010, at 9:20 AM, Michael Roberts wrote:
isNaN Â Â Â Â "simple, byte-order independent test for Not-a-Number"
    ^ self ~= self
so something like this seems a better test
association := #foo -> Float nan. {association} anySatisfy: [:each | each value isNaN]
cheers, Mike
Thank you, it's a good clue :) It's not really cool to have to add special code to test NaN, but if it's the only way ...
NaN is an extremely special case. According to some random forum posting I ran across talking about ISO floating point standards, for example, HUGE_FLOAT * 0 is undefined (which seems ridiculous to me, but there's probably a good reason for it, if it's true...which is really completely beside the point). It might be 0, or it might be NaN. Would you really want that value (in general) to be considered equal to 1/0? In my mind, they've pretty much wound in the same category as SQL's NULL.
Ben
-- James
participants (3)
-
Benjamin -
James Ashley -
Michael Roberts