[Squeak] Newbie permutations
Andrew C. Greenberg
werdna at mucow.com
Tue Apr 9 19:21:00 UTC 2002
It is an implementation concern that should probably be documented. I
imagine it was done this way because it would be inefficient for
applications where copies are not required to have the method make
copies in each instance.
On Tuesday, April 9, 2002, at 03:30 AM, Avi Bryant wrote:
> On Tue, 9 Apr 2002, Duane Maxwell wrote:
>
>>> | foo |
>>> foo := OrderedCollection new.
>>> #(1 3 5) permutationsDo: [:each | foo add: each].
>>>
>>> Does that do it for you?
>>
>> No, unfortunately this gives:
>>
>> an OrderedCollection ( #(1 3 5) #(1 3 5) #(1 3 5) #(1 3 5) #(1 3 5)
>> #(1 3
>> 5) )
>
> Aha. Since this threw me for a second, I should probably explain -
> permutationsDo: is reusing the same array for each permutation. Hence
> the
> need for the #copy in the correct version,
>
> #(1 3 5) permutationsDo: [:each | foo add: each copy]
>
> Is there a widespread convention at work here, or is this just a
> pecularity of the implementation of that particular method?
>
>
More information about the Squeak-dev
mailing list
|