Bug in nested iterations? (was: What is wrong with this?)

Tim Rowledge tim at rowledge.org
Thu May 26 05:17:55 UTC 2005

"Joaquin Sitte" <j.sitte at qut.edu.au> wrote:

> Hi Yoshiki,
> >> map_ Som new: 30
> >> map from: 1 to: map size put: (FloatArray new: 4).
> >  This sets it up so that only one FloatArray instance is created and
> >it will be pointed to by all the 30 slots of 'map' object.
> >  (map first identityHash) = (map last identityHash)
> >will be true.
> This explains the behaviour. But this does not seem to be a terribly useful
> way of doing things, at least not for my purpose. What is the proper way to
> define a  separate vector for every element in the map?

	1 to: map size do:[:i| map at: i put: (FloatArray new: 4)]
would make a new and separate FloatArray object for each iteration.
The problem is that you chanced upon a method that is intended to be a shortcut
way of filling a collection with the >same< object in every slot.

Tim Rowledge, tim at rowledge.org, http://www.rowledge.org/tim
There are no stupid questions. But, there are a lot of inquisitive idiots.

More information about the Squeak-dev mailing list