Tanks, that answer absolutely explain everting Le 30 avr. 2017 10:29 PM, "Sven Van Caekenberghe-2 [via Smalltalk]" < ml+s1294792n4945003h14@n4.nabble.com> a écrit :
Because all 16 elements of the first/top ordered collection contain the exact same element. They are all #==, the same instance/object. If you change one, you change them all.
Here is one way to create what I think you want:
OrderedCollection new: 16 streamContents: [ :out | 16 timesRepeat: [ out nextPut: (OrderedCollection new: 16 withAll: 0) ] ]
BTW, Arrays would be better in this case, I think.
On 30 Apr 2017, at 23:08, frankl1_miky <[hidden email] <http:///user/SendEmail.jtp?type=node&node=4945003&i=0>> wrote:
Hi everyone,
I'm figuring out a strange behavoir with OrderedCollection. Actually I've created a matrix using OrderedCollection like this:
/c := OrderedCollection new: 16 withAll: (OrderedCollection new: 16 withAll: 0). c./ But when I try to set the value at row 1 and column 2 to be 50 like this: /(c at: 1) at: 2 put: 50/ I instead get 50 in any cell of the second column and I don't know why.
When using a Matrix and the massage at:at:put, the behavoir is normal.
Why that strange behavoir with OrderedCollection?
-- View this message in context: http://forum.world.st/ Implement-Matrix-whith-OrderedCollection-tp4945002.html Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
------------------------------ If you reply to this email, your message will be added to the discussion below: http://forum.world.st/Implement-Matrix-whith-OrderedCollection- tp4945002p4945003.html To unsubscribe from Implement Matrix whith OrderedCollection, click here <http://forum.world.st/template/NamlServlet.jtp?macro=unsubscribe_by_code&nod...> . NAML <http://forum.world.st/template/NamlServlet.jtp?macro=macro_viewer&id=instant...>
-- View this message in context: http://forum.world.st/Implement-Matrix-whith-OrderedCollection-tp4945002p494... Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.