On Fri, 29 Mar 2019 at 18:57, Tim Mackinnon <tim@testit.works> wrote:

> Hi Peter - yes of course you are right that its malleable, I guess I’m
> often suprised about the things we leave out and then discover weird things
> we’ve put in.
>
> I had a quick look at LinkedList (I should have thought of that) - I might
> be able to do something with that (and this is now more out of curiosity) -
> but gosh its an easy way to crash your image. Having linked the first to
> the last, and then tried a quick: list after: $n - I’m now guessing I’m
> stuck in an infinite loop that even Cmd . won’t break out of!!!! ouch.
>

If you look at Hier(archy) of LinkList you'll see Semaphore underneath it.
I'm not sure, but there may be some VM magic around Semaphore and Process
management that makes it fragile to changes.
I believe there have been some proposals to separate out the Process
related LinkedList stuff, but I can't remember the exact arguments.

cheers -ben


>
> Tim
>
> On 29 Mar 2019, at 10:20, Peter Kenny <pe...@pbkresearch.co.uk> wrote:
>
> Tim
>
> But the beauty of Smalltalk is that, if you need to use a particular
> structure frequently, you can make it an object just by subclassing
> something useful. In this case, you could create CircularList by
> subclassing
> SequenceableCollection and re-implementing #before and #after (and maybe
> tidying up #add if you don't want the circle to be extendable).
>
> Pursuing this line of thought, we  already have one specialized subclass in
> LinkedList. If the last element is linked to the first, this becomes
> circular. I glanced at some of the methods to see how well this would work,
> but because it regards links as separate from the linked objects, it got
> too
> complicated. But it could give a starting point if you have lots of such
> cases.
>
> HTH
>
> Peter Kenny
>
>
> Tim Mackinnon wrote
>
> 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 &lt;
>
>
> peter@.co
>
>
> &gt; 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
>
>
>
>
>
>
> --
> Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
>
>
>

Reply via email to