<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div dir="ltr">Hi Christoph,</div><div dir="ltr"><br><blockquote type="cite">On Feb 12, 2020, at 9:45 AM, Thiede, Christoph <Christoph.Thiede@student.hpi.uni-potsdam.de> wrote:<br><br></blockquote></div><blockquote type="cite"><div dir="ltr">

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">



<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p>Just in this case, we would rather need something like #copyAsMutable. Otherwise, we would make two copies ..</p></div></div></blockquote>Are you sure? # shuffle is implemented in terms of #shuffleBy: which mutates in ace via #swap:with:<div><br><blockquote type="cite"><div dir="ltr"><div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<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><font size="2" color="#808080"></font></div>
</div>
</div>
</div>
</div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>Von:</b> Squeak-dev <squeak-dev-bounces@lists.squeakfoundation.org> im Auftrag von Eliot Miranda <eliot.miranda@gmail.com><br>
<b>Gesendet:</b> Mittwoch, 12. Februar 2020 18:37:20<br>
<b>An:</b> The general-purpose Squeak developers list<br>
<b>Betreff:</b> Re: [squeak-dev] [BUG] Shuffling an interval raises an error</font>
<div> </div>
</div>
<div>
<div dir="ltr"><br>
</div>
<div dir="ltr"><br>
<blockquote type="cite">On Feb 12, 2020, at 7:25 AM, Thiede, Christoph <Christoph.Thiede@student.hpi.uni-potsdam.de> wrote:<br>
<br>
</blockquote>
</div>
<blockquote type="cite">
<div dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p><b>Code to reproduce:</b></p>
<p>(1 to: 10) shuffled.</p>
<p><br>
</p>
<p><b>Expected behavior:</b></p>
<p>output matches the condition [output sameElements: (1 to: 10)].</p>
<p><br>
</p>
<p><b>Actual behavior:</b></p>
<p>Error: You cannot store into interval!</p>
<p><br>
</p>
<p><b>Considerations:</b></p>
<p>The same problem also exists for: Symbol, ShortRunArray, and SortedCollection which are not modifiable.</p>
<p>#shuffledBy: performs #shuffleBy: on a copy of the receiver.</p>
<p>We could instead use something like (self asModifiable) to ensure that #swap:with: does not fail.</p>
<p>This could basically be [self as: self species], but unfortunately, this is more than three times slower than #copy.</p>
<p>How would you think about:</p>
<blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;">
<p>asModifiable</p>
<p>    self class = self species</p>
<p>        ifTrue: [^ self].</p>
<p>    ^ self as: self species</p>
</blockquote>
<p></p>
<p><br>
</p>
<p>In general, #swap:with: and so #shuffleBy: are only efficient for Arrays and OrderedCollections, but not for RunArrays or LinkedLists.</p>
<p>Should we maybe just convert the receiver into an array in #shuffledBy:? Is #shuffledBy: required to return an object of self species?</p>
</div>
</div>
</blockquote>
<div><br>
</div>
One could add asMutable or asMutableSequence that could also check if an object isReadonly. It would answer self for things that are already mutable (and hopefully soon literals won’t be mutable; we have the change set somewhere), and would answer a mutable
 array for other things.
<div><br>
<div>
<blockquote type="cite">
<div dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p><br>
</p>
<p>Best,</p>
<p>Christoph</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><font size="2" color="#808080"></font></div>
</div>
</div>
</div>
</div>
<span></span><br>
</div>
</blockquote>
</div>
</div>
</div>


<span></span><br></div></blockquote></div></body></html>