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?
Many thanks
Joaquin
===================================================== Dr. Joaquin Sitte, Associate Professor. Head, Smart Devices Lab School of Software Engineering and Data Communication Faculty of Information Technology Queensland University of Technology GPO Box 2434, Brisbane, Q 4001 Australia Phone +61 7 3864 9325 Fax +61 7 3864 9390 e-mail j.sitte@qut.edu.au homepage http://www.fit.qut.edu.au/~sitte http://www.fit.qut.edu.au/~sitte
At 2:15 PM +1000 5/26/05, Joaquin Sitte wrote:
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?
Hi Joaquin,
One simple way would be...
1 to: map size do: [:i | map at: i put: (FloatArray new: 4)]
Cheers,
-- Scott
--------
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?
Dear Scott,
Many thanks for your help. Indeed it makes all the difference! However it seems very subtle to me; in particular if you consider the comment for the method from:to:put: This is the comment: "Put anObject in all indexes between startIndex and endIndex. Very fast. Faster than to:do: for more than 26 positions. Answer anObject"
Certainly tricky for a beginner.
Cheers
Joaquin
_____
From: Scott Wallace [mailto:scott.wallace@squeakland.org] Sent: Thursday, 26 May 2005 15:12 To: Joaquin Sitte Cc: squeak-dev@lists.squeakfoundation.org Subject: Re: Bug in nested iterations? (was: What is wrong with this?)
At 2:15 PM +1000 5/26/05, Joaquin Sitte wrote:
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?
Hi Joaquin,
One simple way would be...
1 to: map size do: [:i | map at: i put: (FloatArray new: 4)]
Cheers,
-- Scott
--------
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?
"Joaquin Sitte" j.sitte@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 -- Tim Rowledge, tim@rowledge.org, http://www.rowledge.org/tim There are no stupid questions. But, there are a lot of inquisitive idiots.
squeak-dev@lists.squeakfoundation.org