<body><div id="__MailbirdStyleContent" style="font-size: 10pt;font-family: Arial;color: #000000">
                                        > <span style="font-family: Calibri, Helvetica, sans-serif;font-size: 16px">Why don't we copy contents when passed in the constructor?</span><div><span style="font-family: Calibri, Helvetica, sans-serif;font-size: 16px"><br></span></div><div><span style="font-family: Calibri, Helvetica, sans-serif;font-size: 16px">Because for most cases, you do not need to do that extra effort. I suppose.</span></div><div><span style="font-family: Calibri, Helvetica, sans-serif;font-size: 16px"><br></span></div><div><span style="font-family: Calibri, Helvetica, sans-serif;font-size: 16px">Best,</span></div><div><span style="font-family: Calibri, Helvetica, sans-serif;font-size: 16px">Marcel</span></div><div class="mb_sig"></div><blockquote class="history_container" type="cite" style="border-left-style:solid;border-width:1px; margin-top:20px; margin-left:0px;padding-left:10px;">
                        <p style="color: #AAAAAA; margin-top: 10px;">Am 19.02.2020 10:29:32 schrieb Thiede, Christoph <christoph.thiede@student.hpi.uni-potsdam.de>:</p><div style="font-family:Arial,Helvetica,sans-serif">

<div id="divtagdefaultwrapper" style="font-size: 12pt;color: #000000;font-family: Calibri,Helvetica,sans-serif" dir="ltr">
<p>Wait, this is indeed interesting! Why don't we copy contents when passed in the constructor? This really feels like an implementation detail of array.</p>
<p><br>
</p>
<p>
<div></div>
<div>block := [Matrix rows: 1 columns: 1 contents: #(1)].</div>
<div>x := block value.</div>
<div>x at: 1 at: 1 put: 2.</div>
<div>y := block value.</div>
<div>self assert: [(y at: 1 at: 1) = 1]. "failed, is 2!"</div>
<div><br>
</div>
<div>Whereas it works if you define block as:</div>
<div><br>
</div>
<div>
<div>"block := [Matrix rows: 1 columns: 1 contents: {1}]."</div>
<div><br>
</div>
</div>
<div>Best,</div>
<div>Christoph</div>
<p>
<div id="Signature">
<div id="divtagdefaultwrapper" dir="ltr" style="font-size: 12pt;color: rgb(0, 0, 0);font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols">
<div name="divtagdefaultwrapper" style="font-family: Calibri,Arial,Helvetica,sans-serif;font-size: ;margin: 0">
<div>
<div class="_rp_T4" id="Item.MessagePartBody">
<div class="_rp_U4 ms-font-weight-regular ms-font-color-neutralDark rpHighlightAllClass rpHighlightBodyClass" id="Item.MessageUniqueBody" style="font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont">
<div dir="ltr">
<div id="divtagdefaultwrapper"><span style="font-family: Calibri,Helvetica,sans-serif,EmojiFont,Apple Color Emoji,Segoe UI Emoji,NotoColorEmoji,Segoe UI Symbol,Android Emoji,EmojiSymbols">
<div id="Signature">
<div style="margin:0px"><font style="font-family:Calibri,Arial,Helvetica,sans-serif,serif,EmojiFont"></font></div>
</div>
</span></div>
</div>
</div>
</div>
</div>
<div><span style="font-size: 10pt;color: #808080"></span></div>
</div>
</div>
</div>
</div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><span style="font-family: Calibri, sans-serif;color: #000000"><b>Von:</b> Squeak-dev <squeak-dev-bounces@lists.squeakfoundation.org> im Auftrag von Taeumel, Marcel<br>
<b>Gesendet:</b> Mittwoch, 19. Februar 2020 10:08:34<br>
<b>An:</b> John Pfersich via Squeak-dev<br>
<b>Betreff:</b> Re: [squeak-dev] [BUG] Issue with Matrix in instance variable</span>
<div> </div>
</div>
<div>
<div id="__MailbirdStyleContent" style="font-size: 10pt;font-family: Arial;color: #000000">
Hi Karl.
<div><br>
</div>
<div>The issue is that, in your example, you are always using the same instance of Array: </div>
<div><br>
</div>
<div>
<div>initialize</div>
<div><span style="white-space:pre"></span>super initialize.</div>
<div><span style="white-space:pre"></span>grid := Matrix rows: 3 columns: 3 contents: #(</div>
<div><span style="white-space:pre"></span>5 3 0 </div>
<div><span style="white-space:pre"></span>6 0 0 </div>
<div><span style="white-space:pre"></span>0 9 8 )</div>
</div>
<div><br>
</div>
<div>Those "contents" will always be the same for each new instance of TesterClass. So, even though the source code reads "#( 5 3 0 ..." is has actually changed to "#( 9 9 9 ...". Try inspecting "TesterClass >> #initalize" and take a look at #literal5:</div>
<div><br>
</div>
<div><img id="e1975963-279e-4ff0-b8ba-4715a61a7d84" width="auto" src="cid:31020277-e79b-4bb0-ba0a-f1540fb09ff2"></img><!-- </img> --><br>
</div>
<div><br>
</div>
<div>This is not a bug. :-) Just a (maybe surprising) side effect of literal arrays.</div>
<div><br>
</div>
<div>Best,</div>
<div>Marcel</div>
<div class="mb_sig"></div>
<blockquote class="history_container" type="cite" style="border-left-style: solid;border-width: 1px;margin-top: 20px;margin-left: 0px;padding-left: 10px;min-width: 500px">
<p style="color: #AAAAAA; margin-top: 10px;">Am 19.02.2020 09:09:03 schrieb karl ramberg <karlramberg@gmail.com>:</p>
<div style="font-family:Arial,Helvetica,sans-serif">
<div dir="ltr">
<div>Hi,</div>
<div>I have this simple class TesterClass new. <br>
</div>
<div>Doit  in Workspace: TesterClass inspect.</div>
<div>The grid instance variable is initialized according to initialize method.<br>
</div>
<div>I doit in inspector: self fillGrid.<br>
</div>
<div>The grid matrix is now filled with all 9.</div>
<div>As expected.<br>
</div>
<div><br>
</div>
<div>Now doit in Workspace: TesterClass new inspect<br>
</div>
<div>The grid is all 9.</div>
<div><br>
</div>
<div>I think the issue is in <br>
</div>
<div>Matrix class>>rows: columns: contents: <br>
</div>
<div>rows: rows columns: columns contents: contents<br>
^super new rows: rows columns: columns contents: contents</div>
<div><br>
</div>
<div>Matrix class overrides new so I think there is a conflict <br>
</div>
<div><br>
</div>
<div>Best,</div>
<div>Karl <br>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<br>
<div><br>
</div>
<div>'From Squeak5.3alpha of 23 October 2019 [latest update: #19139] on 18 February 2020 at 9:22:56 pm'!<br>
Object subclass: #TesterClass<br>
instanceVariableNames: 'grid'<br>
classVariableNames: ''<br>
poolDictionaries: ''<br>
category: 'MyTestStuff'!<br>
<br>
!TesterClass methodsFor: 'as yet unclassified' stamp: 'kfr 2/18/2020 21:21'!<br>
fillGrid<br>
grid atAllPut: 9! !<br>
<br>
!TesterClass methodsFor: 'as yet unclassified' stamp: 'kfr 2/18/2020 21:18'!<br>
initialize<br>
super initialize.<br>
grid := Matrix rows: 3 columns: 3 contents: #(<br>
5 3 0 <br>
6 0 0 <br>
0 9 8 )! !<br>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</div></blockquote>
                                        </div></body>