[Squeak] Newbie permutations

Duane Maxwell dmaxwell at san.rr.com
Tue Apr 9 07:40:08 UTC 2002


From: "Avi Bryant" <avi at beta4.com>
> 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?

I think the current implementation of #permutationsStartingAt:do: is really
to blame here - IMO, any sender of this method would reasonably expect that
each permutation sent to the block is a different object (should fail on #=
and #== with any other permutation), but that is not the case here - it's
the same object with its elements reordered in place.

If it weren't so late, I'd take a stab at cleaning this up while maintaining
efficiency.  Alas, I am afraid I would do more damage than good.

-- Duane




More information about the Squeak-dev mailing list