[Q] SequenceableCollection>>combinations: kk atATimeDo: aBlock

Ken Collins kenncoll123 at hotmail.com
Tue Dec 17 20:05:19 UTC 2002


Perfect! Thanks much :)

Ken





>From: Avi Bryant <avi at beta4.com>
>Reply-To: squeak-dev at lists.squeakfoundation.org
>To: squeak-dev at lists.squeakfoundation.org
>Subject: Re: [Q] SequenceableCollection>>combinations: kk atATimeDo: aBlock
>Date: Tue, 17 Dec 2002 12:10:17 -0800 (PST)
>
>
>On Tue, 17 Dec 2002, Ken Collins wrote:
>
> > ((1 to: 12) combinations: 3 atATimeDo: [:each | Transcript cr; show: 
>each
> > printString])
> >
> > Shows 220 Arrays with 3 parts each. I want to put those Arrays into a 
>new
> > OrderedCollection.
> >
> > |oc|
> > oc_OrderedCollection new.
> > ((1 to: 12) combinations: 3 atATimeDo: [:e | oc add:e]).
> > oc inspect
> >
> > Also shows 220 Arrays with 3 parts each, but they are all #(12 12 12)
> > instead of what shows up in the Transcript.
>
>|oc|
>oc _ OrderedCollection new.
>((1 to: 12) combinations: 3 atATimeDo: [:e | oc add: e copy]).
>oc inspect
>
>I think this came up once before - #combinations:atATimeDo: is reusing the
>same array for each iteration, so you need to explicitly copy it if you
>want to hang on to it.
>
>Avi


_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 2 months FREE*. 
http://join.msn.com/?page=features/featuredemail




More information about the Squeak-dev mailing list