Fwd: for by 3?

--0000000000002707fe059848be24
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Inline:

> ---------- Forwarded message ---------
> From: Simon Proctor <simon.proctor@gmail.com>
> Date: Sat, Nov 23, 2019 at 3:34 AM
> Subject: Re: for by 3?
> To: ToddAndMargo <ToddAndMargo@zoho.com>
> Cc: perl6-users <perl6-users@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;'
=3D=3D=3DSORRY!=3D=3D=3D Error while compiling -e
Malformed parameter
at -e:1
------> my $b; for lines.batch(3) -> $b;=E2=8F=8F<EOL>
mbook:~ homedir$

--0000000000002707fe059848be24
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div di=
r=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"lt=
r"><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div=
 dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D=
"ltr"><div><br></div>Inline:<br><div class=3D"gmail_quote"><blockquote clas=
s=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;b=
order-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"=
>---------- Forwarded message ---------<br>From: <strong class=3D"gmail_sen=
dername" dir=3D"auto">Simon Proctor</strong> <span dir=3D"auto">&lt;<a href=
=3D"mailto:simon.proctor@gmail.com" target=3D"_blank">simon.proctor@gmail.c=
om</a>&gt;<br></span>Date: Sat, Nov 23, 2019 at 3:34 AM<br>Subject: Re: for=
 by 3?<br>To: ToddAndMargo &lt;<a href=3D"mailto:ToddAndMargo@zoho.com" tar=
get=3D"_blank">ToddAndMargo@zoho.com</a>&gt;<br>Cc: perl6-users &lt;<a href=
=3D"mailto:perl6-users@perl.org" target=3D"_blank">perl6-users@perl.org</a>=
&gt;<br><br>If you want to read you lines in groups of 3 then you want batc=
h :<br>for @x.lines.batch(3) -&gt; @b=C2=A0<br>If you just want the third l=
ine and throw away the first I&#39;d probably do a tail on that.<br>for @x.=
lines.batch(3).map( *.tail ) -&gt; $l<br>Note you need to map the tail on e=
ach batch of three not slap it on the end.</blockquote><div dir=3D"auto"><d=
iv dir=3D"auto"><br></div><div dir=3D"auto"><br></div><div>Hi Simon, can yo=
u explain to me what the &quot;-&gt;&quot; arrow is doing in your above? Al=
l I see in the docs is =C2=A0&quot;-&gt;&quot; used within the signature pa=
rt of a sub. I can get some =C2=A0&quot;-&gt;&quot; arrow-containing code t=
o work (below), but it doesn&#39;t resemble your code. Specifically, if I d=
rop the block containing &#39;put&#39;, Raku/Perl6 throws an error.=C2=A0 A=
ny advice appreciated, Bill.</div><div dir=3D"auto"><br></div><div dir=3D"a=
uto"><div><div>mbook:~ homedir$=C2=A0cat testcode5.p6</div><div>first line =
of code</div><div>second line of code</div><div>third line of code</div><di=
v>fourth line of code</div><div>fifth line of code</div><div>mbook:~ homedi=
r$=C2=A0cat testcode5.p6 | perl6 -e &#39;my @b; for lines.batch(3) -&gt; @b=
 {put @b};&#39;</div><div>first line of code second line of code third line=
 of code</div><div>fourth line of code fifth line of code</div><div>mbook:~=
 homedir$=C2=A0cat testcode5.p6 | perl6 -e &#39;my @b; for lines.rotor(3) -=
&gt; @b {put @b};&#39;</div><div>first line of code second line of code thi=
rd line of code</div><div>mbook:~ homedir$ cat testcode5.p6 | perl6 -e &#39=
;my $b; for lines.batch(3) -&gt; $b {put $b};&#39;</div><div>first line of =
code second line of code third line of code</div><div>fourth line of code f=
ifth line of code</div><div>mbook:~ homedir$=C2=A0cat testcode5.p6 | perl6 =
-e &#39;my $b; for lines.batch(3) -&gt; $b;&#39;</div><div>=3D=3D=3DSORRY!=
=3D=3D=3D Error while compiling -e</div><div>Malformed parameter</div><div>=
at -e:1</div><div>------&gt; my $b; for lines.batch(3) -&gt; $b;=E2=8F=8F&l=
t;EOL&gt;</div><div>mbook:~ homedir$=C2=A0</div></div></div></div>
</div></div></div></div></div></div></div></div></div></div></div></div></d=
iv></div></div></div></div></div></div>

--0000000000002707fe059848be24--
0
perl6
11/27/2019 12:04:02 AM
perl.perl6.users 1249 articles. 0 followers. Follow

2 Replies
7 Views

Similar Articles

[PageSpeed] 19

--000000000000006a2705984f35c2
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

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.proctor@gmail.com>
Date: Wed, 27 Nov 2019, 06:59
Subject: Re: for by 3?
To: William Michels <wjm1@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, <wjm1@caa.columbia.edu> wrote:

>
> Inline:
>
>> ---------- Forwarded message ---------
>> From: Simon Proctor <simon.proctor@gmail.com>
>> Date: Sat, Nov 23, 2019 at 3:34 AM
>> Subject: Re: for by 3?
>> To: ToddAndMargo <ToddAndMargo@zoho.com>
>> Cc: perl6-users <perl6-users@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;'
> =3D=3D=3DSORRY!=3D=3D=3D Error while compiling -e
> Malformed parameter
> at -e:1
> ------> my $b; for lines.batch(3) -> $b;=E2=8F=8F<EOL>
> mbook:~ homedir$
>

--000000000000006a2705984f35c2
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"auto"><div>Forgot to reply all this to the list.<div dir=3D"aut=
o"><br></div><div dir=3D"auto">In my defence it&#39;s first thing in the mo=
rning for me.</div><br><br><div class=3D"gmail_quote"><div dir=3D"ltr" clas=
s=3D"gmail_attr">---------- Forwarded message ---------<br>From: <strong cl=
ass=3D"gmail_sendername" dir=3D"auto">Simon Proctor</strong> <span dir=3D"a=
uto">&lt;<a href=3D"mailto:simon.proctor@gmail.com">simon.proctor@gmail.com=
</a>&gt;</span><br>Date: Wed, 27 Nov 2019, 06:59<br>Subject: Re: for by 3?<=
br>To: William Michels &lt;<a href=3D"mailto:wjm1@caa.columbia.edu">wjm1@ca=
a.columbia.edu</a>&gt;<br></div><br><br><div dir=3D"auto">Sorry Bill I was =
typing that on my phone and didn&#39;t fully explain.<div dir=3D"auto"><br>=
</div><div dir=3D"auto">Mostly I didn&#39;t include the block after the @b.=
</div><div dir=3D"auto"><br></div><div dir=3D"auto">-&gt; in Raku is used t=
he pass arguments into a block so this :</div><div dir=3D"auto"><br></div><=
div dir=3D"auto">for @a -&gt; $b { say $b }</div><div dir=3D"auto"><br></di=
v><div dir=3D"auto">Iterates through @a passing each value to the block. Th=
e block lexical scopes the incoming value as $b because of the -&gt;.</div>=
<div dir=3D"auto"><br></div><div dir=3D"auto">The reason you got your error=
 was because you didn&#39;t have a block.</div><div dir=3D"auto"><br></div>=
<div dir=3D"auto">Sorry for the confusion.</div></div><br><div class=3D"gma=
il_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Wed, 27 Nov 2019, 00:04 =
William Michels, &lt;<a href=3D"mailto:wjm1@caa.columbia.edu" target=3D"_bl=
ank" rel=3D"noreferrer">wjm1@caa.columbia.edu</a>&gt; wrote:<br></div><bloc=
kquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #cc=
c solid;padding-left:1ex"><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr=
"><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div =
dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"=
ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><d=
iv dir=3D"ltr"><div dir=3D"ltr"><div><br></div>Inline:<br><div class=3D"gma=
il_quote"><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8=
ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,=
204,204);padding-left:1ex">---------- Forwarded message ---------<br>From: =
<strong class=3D"gmail_sendername" dir=3D"auto">Simon Proctor</strong> <spa=
n dir=3D"auto">&lt;<a href=3D"mailto:simon.proctor@gmail.com" rel=3D"norefe=
rrer noreferrer" target=3D"_blank">simon.proctor@gmail.com</a>&gt;<br></spa=
n>Date: Sat, Nov 23, 2019 at 3:34 AM<br>Subject: Re: for by 3?<br>To: ToddA=
ndMargo &lt;<a href=3D"mailto:ToddAndMargo@zoho.com" rel=3D"noreferrer nore=
ferrer" target=3D"_blank">ToddAndMargo@zoho.com</a>&gt;<br>Cc: perl6-users =
&lt;<a href=3D"mailto:perl6-users@perl.org" rel=3D"noreferrer noreferrer" t=
arget=3D"_blank">perl6-users@perl.org</a>&gt;<br><br>If you want to read yo=
u lines in groups of 3 then you want batch :<br>for @x.lines.batch(3) -&gt;=
 @b=C2=A0<br>If you just want the third line and throw away the first I&#39=
;d probably do a tail on that.<br>for @x.lines.batch(3).map( *.tail ) -&gt;=
 $l<br>Note you need to map the tail on each batch of three not slap it on =
the end.</blockquote><div dir=3D"auto"><div dir=3D"auto"><br></div><div dir=
=3D"auto"><br></div><div>Hi Simon, can you explain to me what the &quot;-&g=
t;&quot; arrow is doing in your above? All I see in the docs is =C2=A0&quot=
;-&gt;&quot; used within the signature part of a sub. I can get some =C2=A0=
&quot;-&gt;&quot; arrow-containing code to work (below), but it doesn&#39;t=
 resemble your code. Specifically, if I drop the block containing &#39;put&=
#39;, Raku/Perl6 throws an error.=C2=A0 Any advice appreciated, Bill.</div>=
<div dir=3D"auto"><br></div><div dir=3D"auto"><div><div>mbook:~ homedir$=C2=
=A0cat testcode5.p6</div><div>first line of code</div><div>second line of c=
ode</div><div>third line of code</div><div>fourth line of code</div><div>fi=
fth line of code</div><div>mbook:~ homedir$=C2=A0cat testcode5.p6 | perl6 -=
e &#39;my @b; for lines.batch(3) -&gt; @b {put @b};&#39;</div><div>first li=
ne of code second line of code third line of code</div><div>fourth line of =
code fifth line of code</div><div>mbook:~ homedir$=C2=A0cat testcode5.p6 | =
perl6 -e &#39;my @b; for lines.rotor(3) -&gt; @b {put @b};&#39;</div><div>f=
irst line of code second line of code third line of code</div><div>mbook:~ =
homedir$ cat testcode5.p6 | perl6 -e &#39;my $b; for lines.batch(3) -&gt; $=
b {put $b};&#39;</div><div>first line of code second line of code third lin=
e of code</div><div>fourth line of code fifth line of code</div><div>mbook:=
~ homedir$=C2=A0cat testcode5.p6 | perl6 -e &#39;my $b; for lines.batch(3) =
-&gt; $b;&#39;</div><div>=3D=3D=3DSORRY!=3D=3D=3D Error while compiling -e<=
/div><div>Malformed parameter</div><div>at -e:1</div><div>------&gt; my $b;=
 for lines.batch(3) -&gt; $b;=E2=8F=8F&lt;EOL&gt;</div><div>mbook:~ homedir=
$=C2=A0</div></div></div></div>
</div></div></div></div></div></div></div></div></div></div></div></div></d=
iv></div></div></div></div></div></div>
</blockquote></div>
</div></div></div>

--000000000000006a2705984f35c2--
0
simon
11/27/2019 7:47:09 AM
> On 27 Nov 2019, at 01:04, William Michels via perl6-users =
<perl6-users@perl.org> wrote:
> 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.

Maybe it becomes clearer when you realize that a sub is nothing but a =
block with a name?

So the same signature options that you see with a sub, are available =
with *ANY* block in Raku:

These two are basically the same thing:

    sub foo($a,$b) { ... }
    foo(42,666);
    dd &foo.name;  # "foo"
    dd &foo.^mro;  # (Sub, Routine, Block, Code, Any, Mu)

    my &foo =3D -> $a, $b { ... }
    foo(42,666);
    dd &foo.name;  # ""
    dd &foo.^mro;  # (Block, Code, Any, Mu)

The only difference is that in the latter case, introspection shows that =
the block doesn't have a name.  And a longer list of parent classes for =
the subroutine case.=
0
liz
11/27/2019 12:09:29 PM
Reply: