comparing objects in a collection

Janet Abdul-Karim jn_karim at yahoo.com
Mon Feb 3 04:44:13 UTC 2003


I am understanding what you said about the difference between #= and #==, but I still get the same result. I am wondering is my logic somehow work or could I possibly be missing some type of punctuation because I know the object is there but it seems to always evaluate the false part and then prints out the type of the object that i am looking for.
 Avi Bryant <avi at beta4.com> wrote:
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




---------------------------------
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20030202/e6616a7e/attachment.htm


More information about the Squeak-dev mailing list