Idea for a possibly better Collection occurrencesOf method.

J J azreal1977 at hotmail.com
Tue Sep 12 06:38:38 UTC 2006


Yea, I think count: or inject: would be better.  Maybe the occurencesOf: 
predates those
methods and that's why they are not used?


>From: "Raymond W. Lucke IV" <smalltalk at raylucke.com>
>Reply-To: The general-purpose Squeak developers 
>list<squeak-dev at lists.squeakfoundation.org>
>To: The general-purpose Squeak developers 
>list<squeak-dev at lists.squeakfoundation.org>
>Subject: Re: Idea for a possibly better Collection occurrencesOf method.
>Date: Mon, 11 Sep 2006 17:29:56 -0700
>
>Hi Zulq,
>
>I didn't see any risks either way, I guess my thought was that it  would be 
>more elegant to not use the temporary variables. Your way is  even more 
>elegant. Is there any performance downside to using count  or inject 
>instead of do with a temporary variable? It would seem to  me that it would 
>be more efficient the way you just described as well.
>
>Ray
>
>
>On Sep 11, 2006, at 5:11 PM, Zulq Alam wrote:
>
>>Raymond W. Lucke IV wrote:
>>
>>>It seems to me that not using inject there might be reinventing  the 
>>>wheel. Please excuse my ignorance if I'm incorrect here, I'm  trying to 
>>>learn Smalltalk and get involved. Any ideas?
>>
>>Is duplication really a problem in this case? I don't think so.  Since you 
>>do, I'm curious what you think the risks are?
>>
>>I do think it could be more readable though.
>>
>>occurrencesOf: anObject
>>   "Answer how many of the receiver's elements are equal to anObject."
>>
>>   ^ self count: [:each | each = anObject]
>>
>>Thanks,
>>Zulq.
>>
>>
>>!DSPAM:4505fab4278191804284693!
>>
>
>





More information about the Squeak-dev mailing list