Forgot to reply all this to the list.

In my defence it's first thing in the morning for me.


---------- Forwarded message ---------
From: Simon Proctor <simon.proc...@gmail.com>
Date: Wed, 27 Nov 2019, 06:59
Subject: Re: for by 3?
To: William Michels <w...@caa.columbia.edu>


Sorry Bill I was typing that on my phone and didn't fully explain.

Mostly I didn't include the block after the @b.

-> in Raku is used the pass arguments into a block so this :

for @a -> $b { say $b }

Iterates through @a passing each value to the block. The block lexical
scopes the incoming value as $b because of the ->.

The reason you got your error was because you didn't have a block.

Sorry for the confusion.

On Wed, 27 Nov 2019, 00:04 William Michels, <w...@caa.columbia.edu> wrote:

>
> Inline:
>
>> ---------- Forwarded message ---------
>> From: Simon Proctor <simon.proc...@gmail.com>
>> Date: Sat, Nov 23, 2019 at 3:34 AM
>> Subject: Re: for by 3?
>> To: ToddAndMargo <toddandma...@zoho.com>
>> Cc: perl6-users <perl6-us...@perl.org>
>>
>> If you want to read you lines in groups of 3 then you want batch :
>> for @x.lines.batch(3) -> @b
>> If you just want the third line and throw away the first I'd probably do
>> a tail on that.
>> for @x.lines.batch(3).map( *.tail ) -> $l
>> Note you need to map the tail on each batch of three not slap it on the
>> end.
>
>
>
> Hi Simon, can you explain to me what the "->" arrow is doing in your
> above? All I see in the docs is  "->" used within the signature part of a
> sub. I can get some  "->" arrow-containing code to work (below), but it
> doesn't resemble your code. Specifically, if I drop the block containing
> 'put', Raku/Perl6 throws an error.  Any advice appreciated, Bill.
>
> mbook:~ homedir$ cat testcode5.p6
> first line of code
> second line of code
> third line of code
> fourth line of code
> fifth line of code
> mbook:~ homedir$ cat testcode5.p6 | perl6 -e 'my @b; for lines.batch(3) ->
> @b {put @b};'
> first line of code second line of code third line of code
> fourth line of code fifth line of code
> mbook:~ homedir$ cat testcode5.p6 | perl6 -e 'my @b; for lines.rotor(3) ->
> @b {put @b};'
> first line of code second line of code third line of code
> mbook:~ homedir$ cat testcode5.p6 | perl6 -e 'my $b; for lines.batch(3) ->
> $b {put $b};'
> first line of code second line of code third line of code
> fourth line of code fifth line of code
> mbook:~ homedir$ cat testcode5.p6 | perl6 -e 'my $b; for lines.batch(3) ->
> $b;'
> ===SORRY!=== Error while compiling -e
> Malformed parameter
> at -e:1
> ------> my $b; for lines.batch(3) -> $b;⏏<EOL>
> mbook:~ homedir$
>

Reply via email to