We could probably mine this forever to get interesting connections, but I shall restrict myself to three (and then shut up). a. The code for SequenceableCollection>>atWrap: is a single line, which exactly reproduces Tim's original method. Maybe a hint for programming strategy - if code is mysterious, encapsulate it in a method with an informative name. b. Modulo reduction to achieve wrapping just works with zero-based indexing. The -1 and +1 can be seen as temporarily converting to zero-based indexing and then converting back. c. If you think of backward shifting more than one place, you end up with a negative index. This works equally well (I checked!), but it is not obvious that it must, because it is not obvious that <negativeInteger> \\ <positiveInteger> has to be positive - I have encountered systems with a different convention. HTH
Peter Kenny Tim Mackinnon wrote > Peter - nice spot. I’m glad we kept this thread running as I keep learning > more of the nooks and crannies. > > I keep finding that between odd naming (although in this case I’m shocked > I missed that one - I need to get better at using spotter) and unfortunate > method categorisation, that I struggle to find these gems. > > If I searched for “wrap”, can I do it over a hierarchy? I need to try > that, as this would eliminate prefix ordering. > > > > Tim > > Sent from my iPhone > >> On 29 Mar 2019, at 17:28, Sven Van Caekenberghe < > sven@ > > wrote: >> >> Haha, great discussion, great find. Amazing that all these things are >> just already there. >> >> Pharo/Smalltalk programming is really 'studying the problem and the >> existing system, moving it to the desired state with as little work as >> possible' - including the use of frameworks and libraries. >> >>> On 29 Mar 2019, at 18:08, Peter Kenny < > peter@.co > > wrote: >>> >>> Tim >>> >>> Going back to your original question, the answer is there all the time >>> but >>> buried in the enormous method dictionaries of the Collection subclasses. >>> If >>> you look at SequenceableCollection>>atWrap: you will see that it does >>> exactly what you want. >>> >>> To get the item before the first, i.e. the zeroth: >>> #(1 2 3 4) atWrap: 0 => 4 >>> >>> To get the item after the last: >>> #(1 2 3 4) atWrap: 5 => 1 >>> >>> As seen here, the method is inherited by Array, so it should do all you >>> want. >>> >>> HTH >>> >>> Peter >>> > >>> Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html >> >> -- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html