Easiest way to wrap around the indexed value in a list (mod doesn't quite work)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
23 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Re: Easiest way to wrap around the indexed value in a list (mod doesn't quite work)

Tim Mackinnon
I actually keep meaning to try and plug this in to spotter so we get all of this stuff in one easy place (I think its pretty simple, just haven’t had a chance to try it yet).

Tim

On 30 Mar 2019, at 09:26, Peter Kenny <[hidden email]> wrote:

Ben

Thanks for pointing this out - I was not aware of it. At first sight the
notation is completely opaque - I had no idea what the query in you post
meant until I read through the instructions in Finder. Now I have tried it,
it looks quite handy.

Minor nit-pick: The instructions say the components of a example are
separated by a period. This should read 'period plus space'; I put in #(1 2
3 4).0.4 as an example and it said no such method. Granted the example
quoted in the instructions has spaces, but a lazy so-and-so like me can be
guaranteed to foul it up.

Peter


Ben Coman wrote
On Sat, 30 Mar 2019 at 01:09, Peter Kenny &lt;

peter@.co

&gt; 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.


And we have Tools > Finder > Examples >  #(10 20 30 40) . 5 . 10
to help unbury such methods...



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



---------------


Marcus Denker-4 wrote
On 29 Mar 2019, at 14:24, Ben Coman &lt;
I believe there have been some proposals to separate out the Process
related LinkedList stuff, but I can't remember the exact arguments.

Yes, we did that… there is now ProcessList.

We ran into that problem far too often “hey, LinkedList can be cleaned
up
easily like this!” —> boom, everything broken.

Now we have ProcessList where it matters if code is changed to
introduce
a
message send more and LinkedList where it does not.


Cool !!

cheers -ben





--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html

Reply | Threaded
Open this post in threaded view
|

Re: Easiest way to wrap around the indexed value in a list (mod doesn't quite work)

Sven Van Caekenberghe-2
Note that 'find by example' seems magical, but it isn't, really. The set of discoverable selectors is limited. See MethodFinder

> On 30 Mar 2019, at 13:26, Tim Mackinnon <[hidden email]> wrote:
>
> I actually keep meaning to try and plug this in to spotter so we get all of this stuff in one easy place (I think its pretty simple, just haven’t had a chance to try it yet).
>
> Tim
>
>> On 30 Mar 2019, at 09:26, Peter Kenny <[hidden email]> wrote:
>>
>> Ben
>>
>> Thanks for pointing this out - I was not aware of it. At first sight the
>> notation is completely opaque - I had no idea what the query in you post
>> meant until I read through the instructions in Finder. Now I have tried it,
>> it looks quite handy.
>>
>> Minor nit-pick: The instructions say the components of a example are
>> separated by a period. This should read 'period plus space'; I put in #(1 2
>> 3 4).0.4 as an example and it said no such method. Granted the example
>> quoted in the instructions has spaces, but a lazy so-and-so like me can be
>> guaranteed to foul it up.
>>
>> Peter
>>
>>
>> Ben Coman wrote
>>> On Sat, 30 Mar 2019 at 01:09, Peter Kenny &lt;
>>
>>> peter@.co
>>
>>> &gt; 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.
>>>
>>>
>>> And we have Tools > Finder > Examples >  #(10 20 30 40) . 5 . 10
>>> to help unbury such methods...
>>>
>>>
>>>
>>>> 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
>>>>
>>>>
>>>
>>> ---------------
>>>
>>>>
>>>> Marcus Denker-4 wrote
>>>>>> On 29 Mar 2019, at 14:24, Ben Coman &lt;
>>>>>> I believe there have been some proposals to separate out the Process
>>>>>> related LinkedList stuff, but I can't remember the exact arguments.
>>>>>
>>>>> Yes, we did that… there is now ProcessList.
>>>>>
>>>>> We ran into that problem far too often “hey, LinkedList can be cleaned
>>>> up
>>>>> easily like this!” —> boom, everything broken.
>>>>>
>>>>> Now we have ProcessList where it matters if code is changed to
>>>> introduce
>>>> a
>>>>> message send more and LinkedList where it does not.
>>>>
>>>
>>> Cool !!
>>>
>>> cheers -ben
>>
>>
>>
>>
>>
>> --
>> Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
>


Reply | Threaded
Open this post in threaded view
|

Re: Easiest way to wrap around the indexed value in a list (mod doesn't quite work)

Peter Kenny
Sven - Thanks for mentioning this - it's fascinating to see how it works.
Even though it's only (!) 900+ selectors, it must have been a nightmare to
construct - the layout of the source code suggests there was a lot of manual
effort. Peter


Sven Van Caekenberghe-2 wrote
> Note that 'find by example' seems magical, but it isn't, really. The set
> of discoverable selectors is limited. See MethodFinder
>
>> On 30 Mar 2019, at 13:26, Tim Mackinnon &lt;

> tim@

> &gt; wrote:
>>
>> I actually keep meaning to try and plug this in to spotter so we get all
>> of this stuff in one easy place (I think its pretty simple, just haven’t
>> had a chance to try it yet).
>>
>> Tim
>>
>>> On 30 Mar 2019, at 09:26, Peter Kenny &lt;

> peter@.co

> &gt; wrote:
>>>
>>> Ben
>>>
>>> Thanks for pointing this out - I was not aware of it. At first sight the
>>> notation is completely opaque - I had no idea what the query in you post
>>> meant until I read through the instructions in Finder. Now I have tried
>>> it,
>>> it looks quite handy.
>>>
>>> Minor nit-pick: The instructions say the components of a example are
>>> separated by a period. This should read 'period plus space'; I put in
>>> #(1 2
>>> 3 4).0.4 as an example and it said no such method. Granted the example
>
>>> Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
>>





--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html

12