Association

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Association

Benjamin Van Ryseghem (Pharo)
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
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users
Reply | Threaded
Open this post in threaded view
|

Re: Association

Michael Roberts-2
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
<[hidden email]> 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
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users
>

_______________________________________________
Pharo-users mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users
Reply | Threaded
Open this post in threaded view
|

Re: Association

Benjamin Van Ryseghem (Pharo)
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

_______________________________________________
Pharo-users mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users
Reply | Threaded
Open this post in threaded view
|

Re: Association

James Ashley
On Tue, Nov 16, 2010 at 3:17 AM, Benjamin
<[hidden email]> 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

_______________________________________________
Pharo-users mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users