comparing objects in a collection

Avi Bryant avi at beta4.com
Mon Feb 3 03:38:48 UTC 2003


On Sun, 2 Feb 2003, Janet Abdul-Karim wrote:

>
> I am trying to find a certain value in a collection.  does something if true or does something if false and for some reason it always evaluates to false and I know its there.  Any help would be great
>
> sample code.
>
> findAccount: accountNumber
>  "Find the account with the argument number"
>
>  self do:[:element | element number == accountNumber
>   ifTrue:([Transcript show: element;cr])
>   ifFalse:([Transcript show: 'No such account exists in this portfolio';cr])].

My guess is that you want to use #= (equality) not #== (identity
equality). Numbers above a certain size are represented in such a way
that they are not the same object even when they are the same number, and
so they are #= but not #==.  For example:

12 = 12 "true"
12 == 12 "true"
(12 raisedTo: 10) = (12 raisedTo: 10) "true"
(12 raisedTo: 10) == (12 raisedTo: 10) "false"

Avi



More information about the Squeak-dev mailing list