Do we have this iterator?

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

Do we have this iterator?

Stephane Ducasse-3
Hi

Did a lot of manual parsing today and I wonder if consumeUntil: would
not have helped me.

#(1 2 3 4 1 2 3 5 6 ) consumeUntil: [:each | each = 4)
>>> {#(1 2 3 4) . #( 1 2 3 5 6 )}

Stef

Reply | Threaded
Open this post in threaded view
|

Re: Do we have this iterator?

Sean P. DeNigris
Administrator
Stephane Ducasse-3 wrote
> #(1 2 3 4 1 2 3 5 6 ) consumeUntil: [:each | each = 4)
>>>> {#(1 2 3 4) . #( 1 2 3 5 6 )}

The shortest kernel thing I could come up with took two steps: `{ #(1 2 3 4
1 2 3 5 6 ) copyUpThrough: 4.
#(1 2 3 4 1 2 3 5 6 ) copyAfter: 4 }`. The splitting messages seem to all
eat the separator.



-----
Cheers,
Sean
--
Sent from: http://forum.world.st/Pharo-Smalltalk-Developers-f1294837.html

Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Do we have this iterator?

Stephane Ducasse-3
Thanks sean.
I will build it because for example I had list of lines and I needed
to split the input depending
on patterns inside the lines.... and sadly this was not for an advent of code.

Rmoders suggested
aggregateRuns:
splitOn:
but this is not the same.


Stef

On Tue, Dec 12, 2017 at 2:33 AM, Sean P. DeNigris <[hidden email]> wrote:

> Stephane Ducasse-3 wrote
>> #(1 2 3 4 1 2 3 5 6 ) consumeUntil: [:each | each = 4)
>>>>> {#(1 2 3 4) . #( 1 2 3 5 6 )}
>
> The shortest kernel thing I could come up with took two steps: `{ #(1 2 3 4
> 1 2 3 5 6 ) copyUpThrough: 4.
> #(1 2 3 4 1 2 3 5 6 ) copyAfter: 4 }`. The splitting messages seem to all
> eat the separator.
>
>
>
> -----
> Cheers,
> Sean
> --
> Sent from: http://forum.world.st/Pharo-Smalltalk-Developers-f1294837.html
>

Reply | Threaded
Open this post in threaded view
|

Re: Do we have this iterator?

tinchodias
If your input was a string instead of a list of lines, you had:

'[^4]*4|.+' asRegex matchesIn: '1234123123456'
>>> 
 "an OrderedCollection('1234' '1231234' '56')"

Martín

On Tue, Dec 12, 2017 at 9:33 AM, Stephane Ducasse <[hidden email]> wrote:
Thanks sean.
I will build it because for example I had list of lines and I needed
to split the input depending
on patterns inside the lines.... and sadly this was not for an advent of code.

Rmoders suggested
aggregateRuns:
splitOn:
but this is not the same.


Stef

On Tue, Dec 12, 2017 at 2:33 AM, Sean P. DeNigris <[hidden email]> wrote:
> Stephane Ducasse-3 wrote
>> #(1 2 3 4 1 2 3 5 6 ) consumeUntil: [:each | each = 4)
>>>>> {#(1 2 3 4) . #( 1 2 3 5 6 )}
>
> The shortest kernel thing I could come up with took two steps: `{ #(1 2 3 4
> 1 2 3 5 6 ) copyUpThrough: 4.
> #(1 2 3 4 1 2 3 5 6 ) copyAfter: 4 }`. The splitting messages seem to all
> eat the separator.
>
>
>
> -----
> Cheers,
> Sean
> --
> Sent from: http://forum.world.st/Pharo-Smalltalk-Developers-f1294837.html
>


Reply | Threaded
Open this post in threaded view
|

Re: Do we have this iterator?

Stephane Ducasse-3
ouaaahhhhhh ;)
My problem was that I had complex lines as elements. and I will not be
able to remember and express anything with regex

On Tue, Dec 12, 2017 at 4:36 PM, Martin Dias <[hidden email]> wrote:

> If your input was a string instead of a list of lines, you had:
>
> '[^4]*4|.+' asRegex matchesIn: '1234123123456'
>>>>
>  "an OrderedCollection('1234' '1231234' '56')"
>
> Martín
>
> On Tue, Dec 12, 2017 at 9:33 AM, Stephane Ducasse <[hidden email]>
> wrote:
>>
>> Thanks sean.
>> I will build it because for example I had list of lines and I needed
>> to split the input depending
>> on patterns inside the lines.... and sadly this was not for an advent of
>> code.
>>
>> Rmoders suggested
>> aggregateRuns:
>> splitOn:
>> but this is not the same.
>>
>>
>> Stef
>>
>> On Tue, Dec 12, 2017 at 2:33 AM, Sean P. DeNigris <[hidden email]>
>> wrote:
>> > Stephane Ducasse-3 wrote
>> >> #(1 2 3 4 1 2 3 5 6 ) consumeUntil: [:each | each = 4)
>> >>>>> {#(1 2 3 4) . #( 1 2 3 5 6 )}
>> >
>> > The shortest kernel thing I could come up with took two steps: `{ #(1 2
>> > 3 4
>> > 1 2 3 5 6 ) copyUpThrough: 4.
>> > #(1 2 3 4 1 2 3 5 6 ) copyAfter: 4 }`. The splitting messages seem to
>> > all
>> > eat the separator.
>> >
>> >
>> >
>> > -----
>> > Cheers,
>> > Sean
>> > --
>> > Sent from:
>> > http://forum.world.st/Pharo-Smalltalk-Developers-f1294837.html
>> >
>>
>

Reply | Threaded
Open this post in threaded view
|

Re: Do we have this iterator?

Nicolas Cellier
Never try to read regexp, it's write only

2017-12-16 9:09 GMT+01:00 Stephane Ducasse <[hidden email]>:
ouaaahhhhhh ;)
My problem was that I had complex lines as elements. and I will not be
able to remember and express anything with regex

On Tue, Dec 12, 2017 at 4:36 PM, Martin Dias <[hidden email]> wrote:
> If your input was a string instead of a list of lines, you had:
>
> '[^4]*4|.+' asRegex matchesIn: '1234123123456'
>>>>
>  "an OrderedCollection('1234' '1231234' '56')"
>
> Martín
>
> On Tue, Dec 12, 2017 at 9:33 AM, Stephane Ducasse <[hidden email]>
> wrote:
>>
>> Thanks sean.
>> I will build it because for example I had list of lines and I needed
>> to split the input depending
>> on patterns inside the lines.... and sadly this was not for an advent of
>> code.
>>
>> Rmoders suggested
>> aggregateRuns:
>> splitOn:
>> but this is not the same.
>>
>>
>> Stef
>>
>> On Tue, Dec 12, 2017 at 2:33 AM, Sean P. DeNigris <[hidden email]>
>> wrote:
>> > Stephane Ducasse-3 wrote
>> >> #(1 2 3 4 1 2 3 5 6 ) consumeUntil: [:each | each = 4)
>> >>>>> {#(1 2 3 4) . #( 1 2 3 5 6 )}
>> >
>> > The shortest kernel thing I could come up with took two steps: `{ #(1 2
>> > 3 4
>> > 1 2 3 5 6 ) copyUpThrough: 4.
>> > #(1 2 3 4 1 2 3 5 6 ) copyAfter: 4 }`. The splitting messages seem to
>> > all
>> > eat the separator.
>> >
>> >
>> >
>> > -----
>> > Cheers,
>> > Sean
>> > --
>> > Sent from:
>> > http://forum.world.st/Pharo-Smalltalk-Developers-f1294837.html
>> >
>>
>


Reply | Threaded
Open this post in threaded view
|

Re: Do we have this iterator?

Ben Coman


On 16 December 2017 at 17:28, Nicolas Cellier <[hidden email]> wrote:
Never try to read regexp, it's write only

its highly susceptible to Kernighan's Lever to shoot yourself in the foot...
   "You separate the bullet from the gun with a hyperoptimized regexp, 
   and then you transport it to your foot using several typeglobs. 
   However, the program fails to run and you can't correct it since 
   you don't understand what the hell it is you've written." 

cheers -ben




2017-12-16 9:09 GMT+01:00 Stephane Ducasse <[hidden email]>:
ouaaahhhhhh ;)
My problem was that I had complex lines as elements. and I will not be
able to remember and express anything with regex

On Tue, Dec 12, 2017 at 4:36 PM, Martin Dias <[hidden email]> wrote:
> If your input was a string instead of a list of lines, you had:
>
> '[^4]*4|.+' asRegex matchesIn: '1234123123456'
>>>>
>  "an OrderedCollection('1234' '1231234' '56')"
>
> Martín
>
> On Tue, Dec 12, 2017 at 9:33 AM, Stephane Ducasse <[hidden email]>
> wrote:
>>
>> Thanks sean.
>> I will build it because for example I had list of lines and I needed
>> to split the input depending
>> on patterns inside the lines.... and sadly this was not for an advent of
>> code.
>>
>> Rmoders suggested
>> aggregateRuns:
>> splitOn:
>> but this is not the same.
>>
>>
>> Stef
>>
>> On Tue, Dec 12, 2017 at 2:33 AM, Sean P. DeNigris <[hidden email]>
>> wrote:
>> > Stephane Ducasse-3 wrote
>> >> #(1 2 3 4 1 2 3 5 6 ) consumeUntil: [:each | each = 4)
>> >>>>> {#(1 2 3 4) . #( 1 2 3 5 6 )}
>> >
>> > The shortest kernel thing I could come up with took two steps: `{ #(1 2
>> > 3 4
>> > 1 2 3 5 6 ) copyUpThrough: 4.
>> > #(1 2 3 4 1 2 3 5 6 ) copyAfter: 4 }`. The splitting messages seem to
>> > all
>> > eat the separator.
>> >
>> >
>> >
>> > -----
>> > Cheers,
>> > Sean
>> > --
>> > Sent from:
>> > http://forum.world.st/Pharo-Smalltalk-Developers-f1294837.html
>> >
>>
>



Reply | Threaded
Open this post in threaded view
|

Re: Do we have this iterator?

Stephane Ducasse-3
So true :)

Stef

On Sat, Dec 16, 2017 at 12:12 PM, Ben Coman <[hidden email]> wrote:

>
>
> On 16 December 2017 at 17:28, Nicolas Cellier
> <[hidden email]> wrote:
>>
>> Never try to read regexp, it's write only
>
>
> its highly susceptible to Kernighan's Lever to shoot yourself in the foot...
>    "You separate the bullet from the gun with a hyperoptimized regexp,
>    and then you transport it to your foot using several typeglobs.
>    However, the program fails to run and you can't correct it since
>    you don't understand what the hell it is you've written."
> http://www.toodarkpark.org/computers/humor/shoot-self-in-foot.html
>
> cheers -ben
>
>
>>
>>
>> 2017-12-16 9:09 GMT+01:00 Stephane Ducasse <[hidden email]>:
>>>
>>> ouaaahhhhhh ;)
>>> My problem was that I had complex lines as elements. and I will not be
>>> able to remember and express anything with regex
>>>
>>> On Tue, Dec 12, 2017 at 4:36 PM, Martin Dias <[hidden email]>
>>> wrote:
>>> > If your input was a string instead of a list of lines, you had:
>>> >
>>> > '[^4]*4|.+' asRegex matchesIn: '1234123123456'
>>> >>>>
>>> >  "an OrderedCollection('1234' '1231234' '56')"
>>> >
>>> > Martín
>>> >
>>> > On Tue, Dec 12, 2017 at 9:33 AM, Stephane Ducasse
>>> > <[hidden email]>
>>> > wrote:
>>> >>
>>> >> Thanks sean.
>>> >> I will build it because for example I had list of lines and I needed
>>> >> to split the input depending
>>> >> on patterns inside the lines.... and sadly this was not for an advent
>>> >> of
>>> >> code.
>>> >>
>>> >> Rmoders suggested
>>> >> aggregateRuns:
>>> >> splitOn:
>>> >> but this is not the same.
>>> >>
>>> >>
>>> >> Stef
>>> >>
>>> >> On Tue, Dec 12, 2017 at 2:33 AM, Sean P. DeNigris
>>> >> <[hidden email]>
>>> >> wrote:
>>> >> > Stephane Ducasse-3 wrote
>>> >> >> #(1 2 3 4 1 2 3 5 6 ) consumeUntil: [:each | each = 4)
>>> >> >>>>> {#(1 2 3 4) . #( 1 2 3 5 6 )}
>>> >> >
>>> >> > The shortest kernel thing I could come up with took two steps: `{
>>> >> > #(1 2
>>> >> > 3 4
>>> >> > 1 2 3 5 6 ) copyUpThrough: 4.
>>> >> > #(1 2 3 4 1 2 3 5 6 ) copyAfter: 4 }`. The splitting messages seem
>>> >> > to
>>> >> > all
>>> >> > eat the separator.
>>> >> >
>>> >> >
>>> >> >
>>> >> > -----
>>> >> > Cheers,
>>> >> > Sean
>>> >> > --
>>> >> > Sent from:
>>> >> > http://forum.world.st/Pharo-Smalltalk-Developers-f1294837.html
>>> >> >
>>> >>
>>> >
>>>
>>
>