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:
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
Carpe Squeak!
|
On Feb 12, 2020, at 7:25 AM, Thiede, Christoph <[hidden email]> wrote:
|
Just in this case, we would rather need something like #copyAsMutable. Otherwise, we would make two copies ... Von: Squeak-dev <[hidden email]> im Auftrag von Eliot Miranda <[hidden email]>
Gesendet: Mittwoch, 12. Februar 2020 18:37:20 An: The general-purpose Squeak developers list Betreff: Re: [squeak-dev] [BUG] Shuffling an interval raises an error On Feb 12, 2020, at 7:25 AM, Thiede, Christoph <[hidden email]> wrote:
Carpe Squeak!
|
Hi Christoph, On Feb 12, 2020, at 9:45 AM, Thiede, Christoph <[hidden email]> wrote: Are you sure? # shuffle is implemented in terms of #shuffleBy: which mutates in ace via #swap:with:
|
Hi Eliot,
how do you propose to implement #shuffledBy: with #asMutable?
[self asMutable shuffleBy: aRandom] would not be guaranteed to preserve the order of the receiver. [self asMutable copy shuffleBy: aRandom] would cause one or two copies.
Best, Christoph Von: Squeak-dev <[hidden email]> im Auftrag von Eliot Miranda <[hidden email]>
Gesendet: Mittwoch, 12. Februar 2020 19:05:37 An: The general-purpose Squeak developers list Betreff: Re: [squeak-dev] [BUG] Shuffling an interval raises an error Hi Christoph,
On Feb 12, 2020, at 9:45 AM, Thiede, Christoph <[hidden email]> wrote: Are you sure? # shuffle is implemented in terms of #shuffleBy: which mutates in ace via #swap:with:
Carpe Squeak!
|
Free forum by Nabble | Edit this page |