a newbie question (disregard earlier message)

Ned Konz ned at bike-nomad.com
Thu Jan 10 02:20:54 UTC 2002


On Wednesday 09 January 2002 02:47 pm, Hari Balaraman wrote:
> Hi all,
>
> I'm attempting to learn Smalltalk and would like to post a small
> question. I apologise in advance if this is is not the appropriate forum
> for basic questions. Is so please point me in the direction of the
> relevant forum. Any assistance will be greatly appreciated.
> Thanks much,
>
> Hari
>
> what follows is the method I wrote for the following problem:  write an
> array in which each element is the square of the corresponding element
> in the receiver array. I cannot find out what I am doing wrong:
>
> arraySquared
>
> 	|squarearray |
>
> 	squarearray := Array new: (self size).
> 		1 	to self size
> 			do: [:index | squarearray at: index put:((self at:
> index)*(self at: index))].
> 	^ squarearray

You should say instead:

         1 to: self size

(you forgot the : at the end of the to).

Or you could just do this:

arraySquared
    ^self collect: [ :ea | ea * ea ]

-- 
Ned Konz
currently: Stanwood, WA
email:     ned at bike-nomad.com
homepage:  http://bike-nomad.com




More information about the Squeak-dev mailing list