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

Eliot Miranda eliot.miranda at gmail.com
Wed Feb 12 17:37:20 UTC 2020



> On Feb 12, 2020, at 7:25 AM, Thiede, Christoph <Christoph.Thiede at student.hpi.uni-potsdam.de> wrote:
> 
> 
> 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?
> 

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.

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


More information about the Squeak-dev mailing list