comparing objects in a collection

Stephane Ducasse ducasse at iam.unibe.ch
Mon Feb 3 08:16:29 UTC 2003


Hi

I have the impression that self should not be your account collections. 
Because this would mean that you are defining a new kind of collection. 
While you certainly want to have an object holding a collection of 
accounts :)


What about

findAccount: aNumber
	^ accountCol select: [:each | each number = accountNumber]

Stef



On Monday, February 3, 2003, at 04:38 AM, Avi Bryant 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
>
>
>
Prof. Dr. Stéphane DUCASSE (ducasse at iam.unibe.ch) 
http://www.iam.unibe.ch/~ducasse/
  "if you knew today was your last day on earth, what would you do
  different? ... especially if, by doing something different, today
  might not be your last day on earth" Calvin&Hobbes




More information about the Squeak-dev mailing list