<div dir="ltr">Interesting! In this code I create two equivalent String objects, then modify a character in one of them. I wondered if it would do a "copy on write", but it did not. The modification affected both which was surprising to me.<div><br></div><div>str1 := 'test'.<br>str2 := 'test'.<br>str1 at: 1 put: $b.<br><br></div><div>In this case, str1 and str2 refer to the same object in memory, so both now have the value "best".</div><div><br></div><div>I suppose the lesson is that literal strings in the same scope might (always?) use the same object in memory.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jul 17, 2024 at 10:12 AM Juan Vuletich <<a href="mailto:juan@cuis.st">juan@cuis.st</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><u></u>
<div bgcolor="#ffffff">
On 7/17/2024 11:08 AM, Mark Volkmann via Cuis-dev wrote:
<blockquote type="cite">
<div dir="ltr">
<div dir="ltr">When I enter the following lines in a Workspace,
select them, and "Do it", I get an AssertionFailure error:
<div><br>
</div>
<div><font face="monospace">str1 := 'test'.<br>
str2 := 'test'.<br>
self assert: str1 ~~ str2.</font><br>
</div>
<div><br>
</div>
<div>Ken, are you saying that you do not get that error?</div>
</div>
<div><br>
</div>
<span class="gmail_signature_prefix">-- </span><br>
<div dir="ltr" class="gmail_signature">
<div dir="ltr">
<div>
<div dir="ltr">
<div>
<div dir="ltr">
<div dir="ltr">
<div><font face="arial, helvetica, sans-serif">R.
Mark Volkmann</font></div>
<div><span style="font-size:12.8px"><font face="arial, helvetica, sans-serif">Object
Computing, Inc.</font></span></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
<br>
Side comment: an AssertionFailure is an Exception but not an Error
(see class hierarchy).<br>
<br>
You get the AssertionFailure if you select all three lines and
evaluate them together, but not if you evaluate them one by one.<br>
<br>
Truth is that str1 and str2 can not be assumed to be the same
object. But they can not be assumed to be different object either.
The compiler is free to reuse the string if it is easy enough.<br>
<br>
Cheers,<br>
<pre cols="72">--
Juan Vuletich
<a href="http://cuis.st" target="_blank">cuis.st</a>
<a href="http://github.com/jvuletich" target="_blank">github.com/jvuletich</a>
<a href="http://researchgate.net/profile/Juan-Vuletich" target="_blank">researchgate.net/profile/Juan-Vuletich</a>
<a href="http://independent.academia.edu/JuanVuletich" target="_blank">independent.academia.edu/JuanVuletich</a>
<a href="http://patents.justia.com/inventor/juan-manuel-vuletich" target="_blank">patents.justia.com/inventor/juan-manuel-vuletich</a>
<a href="http://linkedin.com/in/juan-vuletich-75611b3" target="_blank">linkedin.com/in/juan-vuletich-75611b3</a>
<a href="http://twitter.com/JuanVuletich" target="_blank">twitter.com/JuanVuletich</a></pre>
</div>
</blockquote></div><br clear="all"><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div><font face="arial, helvetica, sans-serif">R. Mark Volkmann</font></div><div><span style="font-size:12.8px"><font face="arial, helvetica, sans-serif">Object Computing, Inc.</font></span></div></div></div></div></div></div></div></div>