Hey thanks guys - while it certainly makes sense when you think about it, I was 
kind of hoping we had something that was much more readable and obvious. It 
seems strange that when we have lots of esoteric things in collection, that 
something which is quite common to do isn’t there. I was kind of hoping we 
might have some circular list or something.

As it stands, if you really want to communicate this clearly you are almost 
better off just doing, the more obvious:

(Index := index - 1) = 0 ifTrue: [index := items size].

Anyway, an interesting one.

Tim

> On 28 Mar 2019, at 16:55, Peter Kenny <pe...@pbkresearch.co.uk> wrote:
> 
> Tim
> 
> I found myself puzzling as to *why* James's solution works. This longer
> explanation helped me to understand.
> 
> First, generalize moving forward to moving an arbitrary number of steps,
> still with wrapping.
> 
> ^list at: (index + move - 1 \\ size + 1
> 
> Second, realize that moving backward one step with wrapping is exactly
> equivalent to moving forward (size - 1) steps - because of wrapping, a move
> of size steps is null.
> 
> Finally, substitute move = size - 1.
> 
> ^list at: (index + size - 2 \\ size + 1.
> 
> This can of course easily generalize to backward moves of any size.
> 
> HTH
> 
> Peter Kenny
> 
> 
> 
> --
> Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
> 


Reply via email to