Populate a new array

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Populate a new array

Jerome Peace
Populate a new array.

On Mar 11, 2007, at 10:40 , Blake wrote:


> Wondering if I'm missing something.

Bert replied:

^(1 to: aQuantity) collect: [:i | stuff]

or alternately can be added:

^Array new: aQuantity withAll: stuff

And depending on context it is probably easier to do
either of these in line than as a method.

Also:

myCollection withAll: stuff

will work if you already have the instance.

Yours in service, --Jerome Peace




 
____________________________________________________________________________________
Looking for earth-friendly autos?
Browse Top Cars by "Green Rating" at Yahoo! Autos' Green Center.
http://autos.yahoo.com/green_center/
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Populate a new array

Bert Freudenberg

On Mar 12, 2007, at 1:29 , Jerome Peace wrote:

> Populate a new array.
>
> On Mar 11, 2007, at 10:40 , Blake wrote:
>
>
>> Wondering if I'm missing something.
>
> Bert replied:
>
> ^(1 to: aQuantity) collect: [:i | stuff]
>
> or alternately can be added:
>
> ^Array new: aQuantity withAll: stuff

Not quite - this will put the same object into each slot. Imagine  
"stuff" being "i squared".

- Bert -


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners