[squeak-dev] [BUG] Shuffling an interval raises an error

Thiede, Christoph Christoph.Thiede at student.hpi.uni-potsdam.de
Wed Feb 12 10:12:57 UTC 2020


Code to reproduce:

(1 to: 10) shuffled.


Expected behavior:

output matches the condition [output sameElements: (1 to: 10)].


Actual behavior:

Error: You cannot store into interval!


Considerations:

The same problem also exists for: Symbol, ShortRunArray, and SortedCollection which are not modifiable.

#shuffledBy: performs #shuffleBy: on a copy of the receiver.

We could instead use something like (self asModifiable) to ensure that #swap:with: does not fail.

This could basically be [self as: self species], but unfortunately, this is more than three times slower than #copy.

How would you think about:

asModifiable

    self class = self species

        ifTrue: [^ self].

    ^ self as: self species


In general, #swap:with: and so #shuffleBy: are only efficient for Arrays and OrderedCollections, but not for RunArrays or LinkedLists.

Should we maybe just convert the receiver into an array in #shuffledBy:? Is #shuffledBy: required to return an object of self species?


Best,

Christoph
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20200212/bc1f2d98/attachment.html>


More information about the Squeak-dev mailing list