<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body 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>
<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>
</body>
</html>