David T. Lewis
lewis at mail.msen.com
Wed Nov 26 23:11:17 UTC 2014
On Wed, Nov 26, 2014 at 11:52:43PM +0100, Frank Lesser wrote:
> Hi Eliiot.
> I am not a native English - but collect: means collect IMO.
> so for every element deliver the result of evaluating the block. DOT
> interesting issue.
I am a native American speaker, so your English is probably better than mine ;-)
I also was surprised by the result. But IdentitySet>>collect: is doing
the right thing in iterating over all the elements of the identity set:
| r |
r := Random new.
((IdentitySet withAll: #(1 2 3 1.0 2.0 3.0))
collect: [:e | r next]) size ==> 6
The confusing behavior is the result of answering a Set rather than IdentitySet.
Eliot argues for answering an IdentitySet, Levente explains why this may
not be a good idea, and Eliot agrees that Levente's suggestion of using
the explicit #collect:as: is a satisfactory solution.
More information about the Squeak-dev