flatten?

Hi All,

I have been using "flatten" for a while.=C2=A0 I kinda-sotra know
what it means.

 From the following,

https://docs.perl6.org/routine/[%20]#language_documentation_Operators

 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 The Array constructor returns an itemized=
 Array that does not
 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 flatten in list context.

What exactly do they mean by "flatten" and "list context"?

Many thanks,
-T
0
tmewell
10/3/2018 12:31:37 AM
perl.perl6.users 1111 articles. 0 followers. Follow

15 Replies
57 Views

Similar Articles

[PageSpeed] 48

On 10/2/18 5:31 PM, Tony Ewell wrote:
> Hi All,
>=20
> I have been using "flatten" for a while.=C2=A0 I kinda-sotra know
> what it means.
>=20
>  From the following,
>=20
> https://docs.perl6.org/routine/[%20]#language_documentation_Operators
>=20
>  =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 The Array constructor returns an itemiz=
ed Array that does not
>  =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 flatten in list context.
>=20
> What exactly do they mean by "flatten" and "list context"?
>=20
> Many thanks,
> -T

Whoever just wrote me on "flatten", would they please
resend.  My iMap server is on the fritz again.
0
perl6
10/5/2018 9:10:06 PM
On 10/5/18 2:10 PM, ToddAndMargo via perl6-users wrote:
> On 10/2/18 5:31 PM, Tony Ewell wrote:
>> Hi All,
>>
>> I have been using "flatten" for a while.=C2=A0 I kinda-sotra know
>> what it means.
>>
>> =C2=A0From the following,
>>
>> https://docs.perl6.org/routine/[%20]#language_documentation_Operators
>>
>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 The Array constructor returns an =
itemized Array that does not
>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 flatten in list context.
>>
>> What exactly do they mean by "flatten" and "list context"?
>>
>> Many thanks,
>> -T
>=20
> Whoever just wrote me on "flatten", would they please
> resend.=C2=A0 My iMap server is on the fritz again.


It just showed up:

> EEEEAEEEE
>     A
>     A
>=20
> Hopefully you see emails in a fixed width font and the As are in a vert=
ical line.
> If not, imagine they were, so there's a T shape.
>=20
> Imagine the horizontal line of four Es, then 3 As vertically, then four=
 more Es, is a list.
>=20
> In this scenario, the horizontal line is a list of 9 elements.
>=20
> The vertical line is an array (which is an "itemized" list) that
> has not flattened into the outer list .
>=20
> If it had flattened, you'd have instead ended up with 11 elements:
>=20
> EEEEAAAEEEE
>=20
> Make sense?
>=20
> --
> raiph
>=20

Thanks raiph!

so

xxxyyyzzz
   a
      b

would show up how?  Or do the letter need
to be the same?
0
perl6
10/5/2018 9:13:41 PM
--000000000000607e260577829b84
Content-Type: text/plain; charset="UTF-8"

Well I guess my first way of explaining it was a complete bust. :)

It's not going to be worth me discussing your reply to my first attempt.

List context means that something appears in the context of a list.

For example, given the list of characters EEEEAEEEE, A appears
in the context of a list of 9 characters.

Flattening a list means creating a new list from an old list such
that any scalar items in the old list are just copied into the new
list and any inner list items in the old list are copied one element
at a time into the new list.

In code:

>  1 ,2, [3,4], 5, 6
( 1 2 [3 4] 5 6)

shows that the resulting list is 5 elements, with the third being
the single list [3,4] because it does *not* flatten in list context.

In contrast, in:

>  1 ,2, |[3,4], 5, 6
( 1 2 3 4 5 6)

we get 6 elements instead because the `|` makes its right hand
side argument flatten into the list context in which it appears.

I won't be surprised to hear that's left you more confused, not less.

If so it'll be time for someone else to try and explain it. :)

--
raiph


On Fri, Oct 5, 2018 at 10:14 PM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> On 10/5/18 2:10 PM, ToddAndMargo via perl6-users wrote:
> > On 10/2/18 5:31 PM, Tony Ewell wrote:
> >> Hi All,
> >>
> >> I have been using "flatten" for a while.  I kinda-sotra know
> >> what it means.
> >>
> >>  From the following,
> >>
> >> https://docs.perl6.org/routine/[%20]#language_documentation_Operators
> <https://docs.perl6.org/routine/%5B%20%5D#language_documentation_Operators>
> >>
> >>        The Array constructor returns an itemized Array that does not
> >>        flatten in list context.
> >>
> >> What exactly do they mean by "flatten" and "list context"?
> >>
> >> Many thanks,
> >> -T
> >
> > Whoever just wrote me on "flatten", would they please
> > resend.  My iMap server is on the fritz again.
>
>
> It just showed up:
>
> > EEEEAEEEE
> >     A
> >     A
> >
> > Hopefully you see emails in a fixed width font and the As are in a
> vertical line.
> > If not, imagine they were, so there's a T shape.
> >
> > Imagine the horizontal line of four Es, then 3 As vertically, then four
> more Es, is a list.
> >
> > In this scenario, the horizontal line is a list of 9 elements.
> >
> > The vertical line is an array (which is an "itemized" list) that
> > has not flattened into the outer list .
> >
> > If it had flattened, you'd have instead ended up with 11 elements:
> >
> > EEEEAAAEEEE
> >
> > Make sense?
> >
> > --
> > raiph
> >
>
> Thanks raiph!
>
> so
>
> xxxyyyzzz
>    a
>       b
>
> would show up how?  Or do the letter need
> to be the same?
>

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

<div dir=3D"ltr"><div>Well I guess my first way of explaining it was a comp=
lete bust. :)</div><div><br></div><div>It&#39;s not going to be worth me di=
scussing your reply to my first attempt.</div><div><br></div>List context m=
eans that something appears in the context of a list.<div><br></div>For exa=
mple, given the list of characters EEEEAEEEE, A appears<div>in the context =
of a list of 9 characters.<br></div><div><br></div><div>Flattening a list m=
eans creating a new list from an old list such</div><div>that any scalar it=
ems in the old list are just copied into the new</div><div>list and any inn=
er list items in the old list are copied one element</div><div>at a time in=
to the new list.</div><div><br></div>In code:<div><div><div><div><br></div>=
<div>&gt;=C2=A0 1 ,2, [3,4], 5, 6</div><div>( 1 2 [3 4] 5 6)</div><div><br>=
</div><div>shows that the resulting list is 5 elements, with the third bein=
g</div><div>the single list [3,4] because it does *not* flatten in list con=
text.</div><div><br></div><div>In contrast, in:</div><div><br></div><div><d=
iv>&gt;=C2=A0 1 ,2, |[3,4], 5, 6</div><div>( 1 2 3 4 5 6)</div><div><br></d=
iv></div>we get 6 elements instead because the `|` makes its right hand</di=
v><div>side argument flatten into the list context in which it appears.</di=
v><div><br></div><div>I won&#39;t be surprised to hear that&#39;s left you =
more confused, not less.</div><br><div>If so it&#39;ll be time for someone =
else to try and explain it. :)<br></div><div><br></div>--</div></div><div>r=
aiph<br></div><div><br></div><div><br><div class=3D"gmail_quote"><div dir=
=3D"ltr">On Fri, Oct 5, 2018 at 10:14 PM ToddAndMargo via perl6-users &lt;<=
a href=3D"mailto:perl6-users@perl.org">perl6-users@perl.org</a>&gt; wrote:<=
br></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;borde=
r-left:1px #ccc solid;padding-left:1ex">On 10/5/18 2:10 PM, ToddAndMargo vi=
a perl6-users wrote:<br>
&gt; On 10/2/18 5:31 PM, Tony Ewell wrote:<br>
&gt;&gt; Hi All,<br>
&gt;&gt;<br>
&gt;&gt; I have been using &quot;flatten&quot; for a while.=C2=A0 I kinda-s=
otra know<br>
&gt;&gt; what it means.<br>
&gt;&gt;<br>
&gt;&gt; =C2=A0From the following,<br>
&gt;&gt;<br>
&gt;&gt; <a href=3D"https://docs.perl6.org/routine/%5B%20%5D#language_docum=
entation_Operators" rel=3D"noreferrer" target=3D"_blank">https://docs.perl6=
..org/routine/[%20]#language_documentation_Operators</a><br>
&gt;&gt;<br>
&gt;&gt; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 The Array constructor returns=
 an itemized Array that does not<br>
&gt;&gt; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 flatten in list context.<br>
&gt;&gt;<br>
&gt;&gt; What exactly do they mean by &quot;flatten&quot; and &quot;list co=
ntext&quot;?<br>
&gt;&gt;<br>
&gt;&gt; Many thanks,<br>
&gt;&gt; -T<br>
&gt; <br>
&gt; Whoever just wrote me on &quot;flatten&quot;, would they please<br>
&gt; resend.=C2=A0 My iMap server is on the fritz again.<br>
<br>
<br>
It just showed up:<br>
<br>
&gt; EEEEAEEEE<br>
&gt;=C2=A0 =C2=A0 =C2=A0A<br>
&gt;=C2=A0 =C2=A0 =C2=A0A<br>
&gt; <br>
&gt; Hopefully you see emails in a fixed width font and the As are in a ver=
tical line.<br>
&gt; If not, imagine they were, so there&#39;s a T shape.<br>
&gt; <br>
&gt; Imagine the horizontal line of four Es, then 3 As vertically, then fou=
r more Es, is a list.<br>
&gt; <br>
&gt; In this scenario, the horizontal line is a list of 9 elements.<br>
&gt; <br>
&gt; The vertical line is an array (which is an &quot;itemized&quot; list) =
that<br>
&gt; has not flattened into the outer list .<br>
&gt; <br>
&gt; If it had flattened, you&#39;d have instead ended up with 11 elements:=
<br>
&gt; <br>
&gt; EEEEAAAEEEE<br>
&gt; <br>
&gt; Make sense?<br>
&gt; <br>
&gt; --<br>
&gt; raiph<br>
&gt; <br>
<br>
Thanks raiph!<br>
<br>
so<br>
<br>
xxxyyyzzz<br>
=C2=A0 =C2=A0a<br>
=C2=A0 =C2=A0 =C2=A0 b<br>
<br>
would show up how?=C2=A0 Or do the letter need<br>
to be the same?<br>
</blockquote></div></div></div>

--000000000000607e260577829b84--
0
ralphdjmellor
10/5/2018 10:15:07 PM
On 10/5/18 3:15 PM, Ralph Mellor wrote:
> Well I guess my first way of explaining it was a complete bust. :)
> 
> It's not going to be worth me discussing your reply to my first attempt.

Hi Ralph,

Thank you!  I am going to have to save it for later and read it
over REAL SLOW!

:-)

-T
0
perl6
10/5/2018 11:43:38 PM
--0000000000002c0c01057784c730
Content-Type: text/plain; charset="UTF-8"

You know how in perl 5, if you do:

   my @a = qw(a b c);
   my @b = (1, @a, 2);

@b will be (1, 'a', 'b', 'c', 2)? That's flattening. $b[1] will be 'a'.
Perl 5 doesn't really understand nested data structures, so you have to
simulate them with refs. If you use [@a] instead, $b[1] will contain an
arrayref that must be dereferenced to get at its contents. (Which it tries
to hide from you by letting you say $b[1][0] instead of $b[1]->[0], which
is what it's really doing. But if you say 'my $c = $b[1]', you need $c->[0]
to get its first item, not $c[0]. Refs are better than what we had to do in
Perl 4 with globs, but they're still kinda icky.)

Perl 6 understands nested lists and other data structures, and doesn't
flatten. If you do the above in Perl 6, you get (1, ('a', 'b', 'c'), 2)
with a nested list. @b[1] is ('a', 'b', 'c') and @b[1][0] is 'a', and
there's no hidden dereference operator involved, nor a "magic" arrayref to
be dereferenced.

On Fri, Oct 5, 2018 at 7:44 PM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> On 10/5/18 3:15 PM, Ralph Mellor wrote:
> > Well I guess my first way of explaining it was a complete bust. :)
> >
> > It's not going to be worth me discussing your reply to my first attempt.
>
> Hi Ralph,
>
> Thank you!  I am going to have to save it for later and read it
> over REAL SLOW!
>
> :-)
>
> -T
>


-- 
brandon s allbery kf8nh
allbery.b@gmail.com

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

<div dir=3D"ltr">You know how in perl 5, if you do:<div><br></div><div>=C2=
=A0 =C2=A0my=C2=A0@a =3D qw(a b c);</div><div>=C2=A0 =C2=A0my=C2=A0@b =3D (=
1,=C2=A0@a, 2);</div><div><br></div><div>@b will be (1, &#39;a&#39;, &#39;b=
&#39;, &#39;c&#39;, 2)? That&#39;s flattening. $b[1] will be &#39;a&#39;. P=
erl 5 doesn&#39;t really understand nested data structures, so you have to =
simulate them with refs.=C2=A0If you use [@a] instead, $b[1] will contain a=
n arrayref that must be dereferenced to get at its contents. (Which it trie=
s to hide from you by letting you say $b[1][0] instead of $b[1]-&gt;[0], wh=
ich is what it&#39;s really doing. But if you say &#39;my $c =3D $b[1]&#39;=
, you need $c-&gt;[0] to get its first item, not $c[0]. Refs are better tha=
n what we had to do in Perl 4 with globs, but they&#39;re still kinda icky.=
)</div><div><br></div><div>Perl 6 understands nested lists and other data s=
tructures, and doesn&#39;t flatten. If you do the above in Perl 6, you get =
(1, (&#39;a&#39;, &#39;b&#39;, &#39;c&#39;), 2) with a nested list.=C2=A0@b=
[1] is (&#39;a&#39;, &#39;b&#39;, &#39;c&#39;) and @b[1][0] is &#39;a&#39;,=
 and there&#39;s no hidden dereference operator involved, nor a &quot;magic=
&quot; arrayref to be dereferenced.</div></div><br><div class=3D"gmail_quot=
e"><div dir=3D"ltr">On Fri, Oct 5, 2018 at 7:44 PM ToddAndMargo via perl6-u=
sers &lt;<a href=3D"mailto:perl6-users@perl.org" target=3D"_blank">perl6-us=
ers@perl.org</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" styl=
e=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 10/5=
/18 3:15 PM, Ralph Mellor wrote:<br>
&gt; Well I guess my first way of explaining it was a complete bust. :)<br>
&gt; <br>
&gt; It&#39;s not going to be worth me discussing your reply to my first at=
tempt.<br>
<br>
Hi Ralph,<br>
<br>
Thank you!=C2=A0 I am going to have to save it for later and read it<br>
over REAL SLOW!<br>
<br>
:-)<br>
<br>
-T<br>
</blockquote></div><br clear=3D"all"><div><br></div>-- <br><div dir=3D"ltr"=
 class=3D"m_5100664693167308300gmail_signature" data-smartmail=3D"gmail_sig=
nature"><div dir=3D"ltr"><div><div dir=3D"ltr"><div>brandon s allbery kf8nh=
</div><div><a href=3D"mailto:allbery.b@gmail.com" target=3D"_blank">allbery=
..b@gmail.com</a></div></div></div></div></div>

--0000000000002c0c01057784c730--
0
allbery
10/6/2018 12:50:33 AM
>> On Fri, Oct 5, 2018 at 7:44 PM ToddAndMargo via perl6-users=20
>> <perl6-users@perl.org <mailto:perl6-users@perl.org>> wrote:
>>=20
>>     On 10/5/18 3:15 PM, Ralph Mellor wrote:
>>      > Well I guess my first way of explaining it was a complete bust.=
 :)
>>      >
>>      > It's not going to be worth me discussing your reply to my first=

>>     attempt.
>>=20
>>     Hi Ralph,
>>=20
>>     Thank you!  I am going to have to save it for later and read it
>>     over REAL SLOW!
>>=20
>>     :-)
>>=20
>>     -T

On 10/5/18 5:50 PM, Brandon Allbery wrote:
> You know how in perl 5, if you do:
>=20
>  =C2=A0 =C2=A0my=C2=A0@a =3D qw(a b c);
>  =C2=A0 =C2=A0my=C2=A0@b =3D (1,=C2=A0@a, 2);
>=20
> @b will be (1, 'a', 'b', 'c', 2)? That's flattening. $b[1] will be 'a'.=
=20
> Perl 5 doesn't really understand nested data structures, so you have to=
=20
> simulate them with refs.=C2=A0If you use [@a] instead, $b[1] will conta=
in an=20
> arrayref that must be dereferenced to get at its contents. (Which it=20
> tries to hide from you by letting you say $b[1][0] instead of=20
> $b[1]->[0], which is what it's really doing. But if you say 'my $c =3D =

> $b[1]', you need $c->[0] to get its first item, not $c[0]. Refs are=20
> better than what we had to do in Perl 4 with globs, but they're still=20
> kinda icky.)
>=20
> Perl 6 understands nested lists and other data structures, and doesn't =

> flatten. If you do the above in Perl 6, you get (1, ('a', 'b', 'c'), 2)=
=20
> with a nested list.=C2=A0@b[1] is ('a', 'b', 'c') and @b[1][0] is 'a', =
and=20
> there's no hidden dereference operator involved, nor a "magic" arrayref=
=20
> to be dereferenced.
>=20

Hi Brandon,

I am following

     my @a =3D qw(a b c);
     my @b =3D (1, @a, 2);

     @b is (1, ('a', 'b', 'c'), 2)

So would flattening @b be (1 a b c 2) ?

If I wanted to assign a flattened @b to @c, how would I do that?

Thank you for the help!

-T
0
perl6
10/6/2018 1:00:48 AM
--00000000000002b8eb0577850c60
Content-Type: text/plain; charset="UTF-8"

That's where the | comes in. If you say

    my @b = (1, |@a, 2);

then you get (1, 'a', 'b', 'c', 2) like in Perl 5. But you can specify what
gets flattened, so you can choose to flatten some arrays but not others if
you need to for some reason:

    my @b = (1, |@b, 2, @b, 3);

gives you (1, 'a', 'b', 'c', 2, ('a', 'b', 'c'), 3). This often matters in
parameter lists, if you want one of the parameters to be the list itself
instead of it being spread across multiple parameters. In Perl 5 you had to
say \@b to pass a ref to the list instead, and the sub had to know it was
getting a scalar containing an arrayref and needed to dereference it (if
you don't know, don't ask; it's ugly).

On Fri, Oct 5, 2018 at 9:01 PM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> >> On Fri, Oct 5, 2018 at 7:44 PM ToddAndMargo via perl6-users
> >> <perl6-users@perl.org <mailto:perl6-users@perl.org>> wrote:
> >>
> >>     On 10/5/18 3:15 PM, Ralph Mellor wrote:
> >>      > Well I guess my first way of explaining it was a complete bust.
> :)
> >>      >
> >>      > It's not going to be worth me discussing your reply to my first
> >>     attempt.
> >>
> >>     Hi Ralph,
> >>
> >>     Thank you!  I am going to have to save it for later and read it
> >>     over REAL SLOW!
> >>
> >>     :-)
> >>
> >>     -T
>
> On 10/5/18 5:50 PM, Brandon Allbery wrote:
> > You know how in perl 5, if you do:
> >
> >     my @a = qw(a b c);
> >     my @b = (1, @a, 2);
> >
> > @b will be (1, 'a', 'b', 'c', 2)? That's flattening. $b[1] will be 'a'.
> > Perl 5 doesn't really understand nested data structures, so you have to
> > simulate them with refs. If you use [@a] instead, $b[1] will contain an
> > arrayref that must be dereferenced to get at its contents. (Which it
> > tries to hide from you by letting you say $b[1][0] instead of
> > $b[1]->[0], which is what it's really doing. But if you say 'my $c =
> > $b[1]', you need $c->[0] to get its first item, not $c[0]. Refs are
> > better than what we had to do in Perl 4 with globs, but they're still
> > kinda icky.)
> >
> > Perl 6 understands nested lists and other data structures, and doesn't
> > flatten. If you do the above in Perl 6, you get (1, ('a', 'b', 'c'), 2)
> > with a nested list. @b[1] is ('a', 'b', 'c') and @b[1][0] is 'a', and
> > there's no hidden dereference operator involved, nor a "magic" arrayref
> > to be dereferenced.
> >
>
> Hi Brandon,
>
> I am following
>
>      my @a = qw(a b c);
>      my @b = (1, @a, 2);
>
>      @b is (1, ('a', 'b', 'c'), 2)
>
> So would flattening @b be (1 a b c 2) ?
>
> If I wanted to assign a flattened @b to @c, how would I do that?
>
> Thank you for the help!
>
> -T
>


-- 
brandon s allbery kf8nh
allbery.b@gmail.com

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

<div dir=3D"ltr">That&#39;s where the | comes in. If you say<div><br></div>=
<div>=C2=A0 =C2=A0 my=C2=A0@b =3D (1, |@a, 2);</div><div><br></div><div>the=
n you get (1, &#39;a&#39;, &#39;b&#39;, &#39;c&#39;, 2) like in Perl 5. But=
 you can specify what gets flattened, so you can choose to flatten some arr=
ays but not others if you need to for some reason:</div><div><br></div><div=
>=C2=A0 =C2=A0 my=C2=A0@b =3D (1, |@b, 2,=C2=A0@b, 3);</div><div><br></div>=
<div>gives you (1, &#39;a&#39;, &#39;b&#39;, &#39;c&#39;, 2, (&#39;a&#39;, =
&#39;b&#39;, &#39;c&#39;), 3). This often matters in parameter lists, if yo=
u want one of the parameters to be the list itself instead of it being spre=
ad across multiple parameters. In Perl 5 you had to say \@b to pass a ref t=
o the list instead, and the sub had to know it was getting a scalar contain=
ing an arrayref and needed to dereference it (if you don&#39;t know, don&#3=
9;t ask; it&#39;s ugly).</div></div><br><div class=3D"gmail_quote"><div dir=
=3D"ltr">On Fri, Oct 5, 2018 at 9:01 PM ToddAndMargo via perl6-users &lt;<a=
 href=3D"mailto:perl6-users@perl.org" target=3D"_blank">perl6-users@perl.or=
g</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin=
:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">&gt;&gt; On Fri, O=
ct 5, 2018 at 7:44 PM ToddAndMargo via perl6-users <br>
&gt;&gt; &lt;<a href=3D"mailto:perl6-users@perl.org" target=3D"_blank">perl=
6-users@perl.org</a> &lt;mailto:<a href=3D"mailto:perl6-users@perl.org" tar=
get=3D"_blank">perl6-users@perl.org</a>&gt;&gt; wrote:<br>
&gt;&gt; <br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0On 10/5/18 3:15 PM, Ralph Mellor wrote:<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 &gt; Well I guess my first way of explaining i=
t was a complete bust. :)<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 &gt;<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 &gt; It&#39;s not going to be worth me discuss=
ing your reply to my first<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0attempt.<br>
&gt;&gt; <br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0Hi Ralph,<br>
&gt;&gt; <br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0Thank you!=C2=A0 I am going to have to save it =
for later and read it<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0over REAL SLOW!<br>
&gt;&gt; <br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0:-)<br>
&gt;&gt; <br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0-T<br>
<br>
On 10/5/18 5:50 PM, Brandon Allbery wrote:<br>
&gt; You know how in perl 5, if you do:<br>
&gt; <br>
&gt;=C2=A0 =C2=A0 =C2=A0my=C2=A0@a =3D qw(a b c);<br>
&gt;=C2=A0 =C2=A0 =C2=A0my=C2=A0@b =3D (1,=C2=A0@a, 2);<br>
&gt; <br>
&gt; @b will be (1, &#39;a&#39;, &#39;b&#39;, &#39;c&#39;, 2)? That&#39;s f=
lattening. $b[1] will be &#39;a&#39;. <br>
&gt; Perl 5 doesn&#39;t really understand nested data structures, so you ha=
ve to <br>
&gt; simulate them with refs.=C2=A0If you use [@a] instead, $b[1] will cont=
ain an <br>
&gt; arrayref that must be dereferenced to get at its contents. (Which it <=
br>
&gt; tries to hide from you by letting you say $b[1][0] instead of <br>
&gt; $b[1]-&gt;[0], which is what it&#39;s really doing. But if you say &#3=
9;my $c =3D <br>
&gt; $b[1]&#39;, you need $c-&gt;[0] to get its first item, not $c[0]. Refs=
 are <br>
&gt; better than what we had to do in Perl 4 with globs, but they&#39;re st=
ill <br>
&gt; kinda icky.)<br>
&gt; <br>
&gt; Perl 6 understands nested lists and other data structures, and doesn&#=
39;t <br>
&gt; flatten. If you do the above in Perl 6, you get (1, (&#39;a&#39;, &#39=
;b&#39;, &#39;c&#39;), 2) <br>
&gt; with a nested list.=C2=A0@b[1] is (&#39;a&#39;, &#39;b&#39;, &#39;c&#3=
9;) and @b[1][0] is &#39;a&#39;, and <br>
&gt; there&#39;s no hidden dereference operator involved, nor a &quot;magic=
&quot; arrayref <br>
&gt; to be dereferenced.<br>
&gt; <br>
<br>
Hi Brandon,<br>
<br>
I am following<br>
<br>
=C2=A0 =C2=A0 =C2=A0my @a =3D qw(a b c);<br>
=C2=A0 =C2=A0 =C2=A0my @b =3D (1, @a, 2);<br>
<br>
=C2=A0 =C2=A0 =C2=A0@b is (1, (&#39;a&#39;, &#39;b&#39;, &#39;c&#39;), 2)<b=
r>
<br>
So would flattening @b be (1 a b c 2) ?<br>
<br>
If I wanted to assign a flattened @b to @c, how would I do that?<br>
<br>
Thank you for the help!<br>
<br>
-T<br>
</blockquote></div><br clear=3D"all"><div><br></div>-- <br><div dir=3D"ltr"=
 class=3D"m_-5132706820669398265gmail_signature" data-smartmail=3D"gmail_si=
gnature"><div dir=3D"ltr"><div><div dir=3D"ltr"><div>brandon s allbery kf8n=
h</div><div><a href=3D"mailto:allbery.b@gmail.com" target=3D"_blank">allber=
y.b@gmail.com</a></div></div></div></div></div>

--00000000000002b8eb0577850c60--
0
allbery
10/6/2018 1:09:46 AM
On 10/5/18 6:09 PM, Brandon Allbery wrote:
> That's where the | comes in. If you say
>=20
>  =C2=A0 =C2=A0 my=C2=A0@b =3D (1, |@a, 2);
>=20
> then you get (1, 'a', 'b', 'c', 2) like in Perl 5. But you can specify =

> what gets flattened, so you can choose to flatten some arrays but not=20
> others if you need to for some reason:
>=20
>  =C2=A0 =C2=A0 my=C2=A0@b =3D (1, |@b, 2,=C2=A0@b, 3);
>=20
> gives you (1, 'a', 'b', 'c', 2, ('a', 'b', 'c'), 3). This often matters=
=20
> in parameter lists, if you want one of the parameters to be the list=20
> itself instead of it being spread across multiple parameters. In Perl 5=
=20
> you had to say \@b to pass a ref to the list instead, and the sub had t=
o=20
> know it was getting a scalar containing an arrayref and needed to=20
> dereference it (if you don't know, don't ask; it's ugly).

Am I correct in my assumption?

A little off the question, but how do I address something
inside a nested array?

In the following, how do I get at the "b"


$ p6 'my @x=3D<a b c>; my @y=3D<1 2 @x 3 4>; say @y; dd @y;'

[1 2 @x 3 4]

Array @y =3D [IntStr.new(1, "1"), IntStr.new(2, "2"), "\@x", IntStr.new(3=
,=20
"3"), IntStr.new(4, "4")]

Also, how do I flatten @y above?

Thank you for the help!
-T
0
perl6
10/6/2018 1:22:44 AM
--00000000000095f4880577854e20
Content-Type: text/plain; charset="UTF-8"

You can't with that, because < ... > acts like single quotes; '@x' there is
a string literal, not the list @x. If you use << ... >> then it act like
double quotes, and will use the list instead.

On Fri, Oct 5, 2018 at 9:23 PM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> On 10/5/18 6:09 PM, Brandon Allbery wrote:
> > That's where the | comes in. If you say
> >
> >      my @b = (1, |@a, 2);
> >
> > then you get (1, 'a', 'b', 'c', 2) like in Perl 5. But you can specify
> > what gets flattened, so you can choose to flatten some arrays but not
> > others if you need to for some reason:
> >
> >      my @b = (1, |@b, 2, @b, 3);
> >
> > gives you (1, 'a', 'b', 'c', 2, ('a', 'b', 'c'), 3). This often matters
> > in parameter lists, if you want one of the parameters to be the list
> > itself instead of it being spread across multiple parameters. In Perl 5
> > you had to say \@b to pass a ref to the list instead, and the sub had to
> > know it was getting a scalar containing an arrayref and needed to
> > dereference it (if you don't know, don't ask; it's ugly).
>
> Am I correct in my assumption?
>
> A little off the question, but how do I address something
> inside a nested array?
>
> In the following, how do I get at the "b"
>
>
> $ p6 'my @x=<a b c>; my @y=<1 2 @x 3 4>; say @y; dd @y;'
>
> [1 2 @x 3 4]
>
> Array @y = [IntStr.new(1, "1"), IntStr.new(2, "2"), "\@x", IntStr.new(3,
> "3"), IntStr.new(4, "4")]
>
> Also, how do I flatten @y above?
>
> Thank you for the help!
> -T
>


-- 
brandon s allbery kf8nh
allbery.b@gmail.com

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

<div dir=3D"ltr">You can&#39;t with that, because &lt; ... &gt; acts like s=
ingle quotes; &#39;@x&#39; there is a string literal, not the list @x. If y=
ou use &lt;&lt; ... &gt;&gt; then it act like double quotes, and will use t=
he list instead.</div><br><div class=3D"gmail_quote"><div dir=3D"ltr">On Fr=
i, Oct 5, 2018 at 9:23 PM ToddAndMargo via perl6-users &lt;<a href=3D"mailt=
o:perl6-users@perl.org">perl6-users@perl.org</a>&gt; wrote:<br></div><block=
quote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc=
 solid;padding-left:1ex">On 10/5/18 6:09 PM, Brandon Allbery wrote:<br>
&gt; That&#39;s where the | comes in. If you say<br>
&gt; <br>
&gt;=C2=A0 =C2=A0 =C2=A0 my=C2=A0@b =3D (1, |@a, 2);<br>
&gt; <br>
&gt; then you get (1, &#39;a&#39;, &#39;b&#39;, &#39;c&#39;, 2) like in Per=
l 5. But you can specify <br>
&gt; what gets flattened, so you can choose to flatten some arrays but not =
<br>
&gt; others if you need to for some reason:<br>
&gt; <br>
&gt;=C2=A0 =C2=A0 =C2=A0 my=C2=A0@b =3D (1, |@b, 2,=C2=A0@b, 3);<br>
&gt; <br>
&gt; gives you (1, &#39;a&#39;, &#39;b&#39;, &#39;c&#39;, 2, (&#39;a&#39;, =
&#39;b&#39;, &#39;c&#39;), 3). This often matters <br>
&gt; in parameter lists, if you want one of the parameters to be the list <=
br>
&gt; itself instead of it being spread across multiple parameters. In Perl =
5 <br>
&gt; you had to say \@b to pass a ref to the list instead, and the sub had =
to <br>
&gt; know it was getting a scalar containing an arrayref and needed to <br>
&gt; dereference it (if you don&#39;t know, don&#39;t ask; it&#39;s ugly).<=
br>
<br>
Am I correct in my assumption?<br>
<br>
A little off the question, but how do I address something<br>
inside a nested array?<br>
<br>
In the following, how do I get at the &quot;b&quot;<br>
<br>
<br>
$ p6 &#39;my @x=3D&lt;a b c&gt;; my @y=3D&lt;1 2 @x 3 4&gt;; say @y; dd @y;=
&#39;<br>
<br>
[1 2 @x 3 4]<br>
<br>
Array @y =3D [IntStr.new(1, &quot;1&quot;), IntStr.new(2, &quot;2&quot;), &=
quot;\@x&quot;, IntStr.new(3, <br>
&quot;3&quot;), IntStr.new(4, &quot;4&quot;)]<br>
<br>
Also, how do I flatten @y above?<br>
<br>
Thank you for the help!<br>
-T<br>
</blockquote></div><br clear=3D"all"><div><br></div>-- <br><div dir=3D"ltr"=
 class=3D"gmail_signature" data-smartmail=3D"gmail_signature"><div dir=3D"l=
tr"><div><div dir=3D"ltr"><div>brandon s allbery kf8nh</div><div><a href=3D=
"mailto:allbery.b@gmail.com" target=3D"_blank">allbery.b@gmail.com</a></div=
></div></div></div></div>

--00000000000095f4880577854e20--
0
allbery
10/6/2018 1:28:18 AM
On 10/5/18 6:28 PM, Brandon Allbery wrote:
> You can't with that, because < ... > acts like single quotes; '@x' ther=
e=20
> is a string literal, not the list @x. If you use << ... >> then it act =

> like double quotes, and will use the list instead.

I am sorry.  With the top posting, I can't tell
what you are talking about.  I also can't tell which
of the three question I asked that you are
answering

:'(

>=20
> On Fri, Oct 5, 2018 at 9:23 PM ToddAndMargo via perl6-users=20
> <perl6-users@perl.org <mailto:perl6-users@perl.org>> wrote:
>=20
>     On 10/5/18 6:09 PM, Brandon Allbery wrote:
>      > That's where the | comes in. If you say
>      >
>      >=C2=A0 =C2=A0 =C2=A0 my=C2=A0@b =3D (1, |@a, 2);
>      >
>      > then you get (1, 'a', 'b', 'c', 2) like in Perl 5. But you can
>     specify
>      > what gets flattened, so you can choose to flatten some arrays bu=
t
>     not
>      > others if you need to for some reason:
>      >
>      >=C2=A0 =C2=A0 =C2=A0 my=C2=A0@b =3D (1, |@b, 2,=C2=A0@b, 3);
>      >
>      > gives you (1, 'a', 'b', 'c', 2, ('a', 'b', 'c'), 3). This often
>     matters
>      > in parameter lists, if you want one of the parameters to be the =
list
>      > itself instead of it being spread across multiple parameters. In=

>     Perl 5
>      > you had to say \@b to pass a ref to the list instead, and the su=
b
>     had to
>      > know it was getting a scalar containing an arrayref and needed t=
o
>      > dereference it (if you don't know, don't ask; it's ugly).
>=20
>     Am I correct in my assumption?
>=20
>     A little off the question, but how do I address something
>     inside a nested array?
>=20
>     In the following, how do I get at the "b"
>=20
>=20
>     $ p6 'my @x=3D<a b c>; my @y=3D<1 2 @x 3 4>; say @y; dd @y;'
>=20
>     [1 2 @x 3 4]
>=20
>     Array @y =3D [IntStr.new(1, "1"), IntStr.new(2, "2"), "\@x",
>     IntStr.new(3,
>     "3"), IntStr.new(4, "4")]
>=20
>     Also, how do I flatten @y above?
>=20
>     Thank you for the help!
>     -T
>=20
>=20
>=20
> --=20
> brandon s allbery kf8nh
> allbery.b@gmail.com <mailto:allbery.b@gmail.com>


--=20
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Computers are like air conditioners.
They malfunction when you open windows
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0
perl6
10/6/2018 3:27:10 AM
--000000000000e5639f0577874860
Content-Type: text/plain; charset="UTF-8"

Turns out I misspoke anyway; << >> isn't enough by itself.

$ p6 'my @x=<a b c>; my @y=<<1 2 @x 3 4>>; say @y; dd @y;'

@y will contain (1, 2, '@x', 3, 4). (Actually, the numbers will be things
that are simultaneously numbers and strings, showing up as IntStr.new(1,
'1') and such.) '@x' is a two-character string, not the list @x or its
contents.

    pyanfar Z$ 6 'my @x = <a b c>; my @y = <<1 2 @x[] 3 4>>; dd @y'
    Array @y = [IntStr.new(1, "1"), IntStr.new(2, "2"), "a", "b", "c",
IntStr.new(3, "3"), IntStr.new(4, "4")]

Which flattens because it's interpolating values, since quoting constructs
produce string-like things or lists of string-like things (role Stringy),
not lists of lists. If you want a list of lists, you are better off just
using lists directly, not the quoting constructs that are intended to give
you lists of strings. This is similar to Perl 5, where qw() also doesn't
expand variables:

    pyanfar Z$ perl -MData::Dumper -E 'my @x = qw(a b c); my @y = qw(1 @x
2); say Dumper(\@y)'
    $VAR1 = [
              '1',
              '@x',
              '2'
            ];


On Fri, Oct 5, 2018 at 11:27 PM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> On 10/5/18 6:28 PM, Brandon Allbery wrote:
> > You can't with that, because < ... > acts like single quotes; '@x' there
> > is a string literal, not the list @x. If you use << ... >> then it act
> > like double quotes, and will use the list instead.
>
> I am sorry.  With the top posting, I can't tell
> what you are talking about.  I also can't tell which
> of the three question I asked that you are
> answering
>
> :'(
>
> >
> > On Fri, Oct 5, 2018 at 9:23 PM ToddAndMargo via perl6-users
> > <perl6-users@perl.org <mailto:perl6-users@perl.org>> wrote:
> >
> >     On 10/5/18 6:09 PM, Brandon Allbery wrote:
> >      > That's where the | comes in. If you say
> >      >
> >      >      my @b = (1, |@a, 2);
> >      >
> >      > then you get (1, 'a', 'b', 'c', 2) like in Perl 5. But you can
> >     specify
> >      > what gets flattened, so you can choose to flatten some arrays but
> >     not
> >      > others if you need to for some reason:
> >      >
> >      >      my @b = (1, |@b, 2, @b, 3);
> >      >
> >      > gives you (1, 'a', 'b', 'c', 2, ('a', 'b', 'c'), 3). This often
> >     matters
> >      > in parameter lists, if you want one of the parameters to be the
> list
> >      > itself instead of it being spread across multiple parameters. In
> >     Perl 5
> >      > you had to say \@b to pass a ref to the list instead, and the sub
> >     had to
> >      > know it was getting a scalar containing an arrayref and needed to
> >      > dereference it (if you don't know, don't ask; it's ugly).
> >
> >     Am I correct in my assumption?
> >
> >     A little off the question, but how do I address something
> >     inside a nested array?
> >
> >     In the following, how do I get at the "b"
> >
> >
> >     $ p6 'my @x=<a b c>; my @y=<1 2 @x 3 4>; say @y; dd @y;'
> >
> >     [1 2 @x 3 4]
> >
> >     Array @y = [IntStr.new(1, "1"), IntStr.new(2, "2"), "\@x",
> >     IntStr.new(3,
> >     "3"), IntStr.new(4, "4")]
> >
> >     Also, how do I flatten @y above?
> >
> >     Thank you for the help!
> >     -T
> >
> >
> >
> > --
> > brandon s allbery kf8nh
> > allbery.b@gmail.com <mailto:allbery.b@gmail.com>
>
>
> --
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Computers are like air conditioners.
> They malfunction when you open windows
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>


-- 
brandon s allbery kf8nh
allbery.b@gmail.com

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

<div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr">Turns out I misspoke any=
way; &lt;&lt; &gt;&gt; isn&#39;t enough by itself.<div><br></div><div><span=
 style=3D"color:rgb(80,0,80)">$ p6 &#39;my @x=3D&lt;a b c&gt;; my @y=3D&lt;=
&lt;1 2 @x 3 4&gt;&gt;; say @y; dd @y;&#39;</span><br></div><br>@y will con=
tain (1, 2, &#39;@x&#39;, 3, 4). (Actually, the numbers will be things that=
 are simultaneously numbers and strings, showing up as IntStr.new(1, &#39;1=
&#39;) and such.) &#39;@x&#39; is a two-character string, not the list=C2=
=A0@x or its contents.<div><br></div><div>=C2=A0 =C2=A0 pyanfar Z$ 6 &#39;m=
y @x =3D &lt;a b c&gt;; my @y =3D &lt;&lt;1 2 @x[] 3 4&gt;&gt;; dd @y&#39;<=
/div><div>=C2=A0 =C2=A0 Array @y =3D [IntStr.new(1, &quot;1&quot;), IntStr.=
new(2, &quot;2&quot;), &quot;a&quot;, &quot;b&quot;, &quot;c&quot;, IntStr.=
new(3, &quot;3&quot;), IntStr.new(4, &quot;4&quot;)]</div><div><br></div><d=
iv>Which flattens because it&#39;s interpolating values, since quoting cons=
tructs produce string-like things or lists of string-like things (role Stri=
ngy), not lists of lists. If you want a list of lists, you are better off j=
ust using lists directly, not the quoting constructs that are intended to g=
ive you lists of strings. This is similar to Perl 5, where qw() also doesn&=
#39;t expand variables:</div><div><br></div><div><div>=C2=A0 =C2=A0 pyanfar=
 Z$ perl -MData::Dumper -E &#39;my @x =3D qw(a b c); my @y =3D qw(1 @x 2); =
say Dumper(\@y)&#39;</div><div>=C2=A0 =C2=A0 $VAR1 =3D [</div><div>=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 &#39;1&#39;,</div><div>=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 &#39;@x&#39;,</div><div>=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 &#39;2&#39;</div><div>=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 ];</div></div><div><br></div></div></div></div>=
<br><div class=3D"gmail_quote"><div dir=3D"ltr">On Fri, Oct 5, 2018 at 11:2=
7 PM ToddAndMargo via perl6-users &lt;<a href=3D"mailto:perl6-users@perl.or=
g">perl6-users@perl.org</a>&gt; wrote:<br></div><blockquote class=3D"gmail_=
quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1=
ex">On 10/5/18 6:28 PM, Brandon Allbery wrote:<br>
&gt; You can&#39;t with that, because &lt; ... &gt; acts like single quotes=
; &#39;@x&#39; there <br>
&gt; is a string literal, not the list @x. If you use &lt;&lt; ... &gt;&gt;=
 then it act <br>
&gt; like double quotes, and will use the list instead.<br>
<br>
I am sorry.=C2=A0 With the top posting, I can&#39;t tell<br>
what you are talking about.=C2=A0 I also can&#39;t tell which<br>
of the three question I asked that you are<br>
answering<br>
<br>
:&#39;(<br>
<br>
&gt; <br>
&gt; On Fri, Oct 5, 2018 at 9:23 PM ToddAndMargo via perl6-users <br>
&gt; &lt;<a href=3D"mailto:perl6-users@perl.org" target=3D"_blank">perl6-us=
ers@perl.org</a> &lt;mailto:<a href=3D"mailto:perl6-users@perl.org" target=
=3D"_blank">perl6-users@perl.org</a>&gt;&gt; wrote:<br>
&gt; <br>
&gt;=C2=A0 =C2=A0 =C2=A0On 10/5/18 6:09 PM, Brandon Allbery wrote:<br>
&gt;=C2=A0 =C2=A0 =C2=A0 &gt; That&#39;s where the | comes in. If you say<b=
r>
&gt;=C2=A0 =C2=A0 =C2=A0 &gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0 &gt;=C2=A0 =C2=A0 =C2=A0 my=C2=A0@b =3D (1, |@a, 2=
);<br>
&gt;=C2=A0 =C2=A0 =C2=A0 &gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0 &gt; then you get (1, &#39;a&#39;, &#39;b&#39;, &#=
39;c&#39;, 2) like in Perl 5. But you can<br>
&gt;=C2=A0 =C2=A0 =C2=A0specify<br>
&gt;=C2=A0 =C2=A0 =C2=A0 &gt; what gets flattened, so you can choose to fla=
tten some arrays but<br>
&gt;=C2=A0 =C2=A0 =C2=A0not<br>
&gt;=C2=A0 =C2=A0 =C2=A0 &gt; others if you need to for some reason:<br>
&gt;=C2=A0 =C2=A0 =C2=A0 &gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0 &gt;=C2=A0 =C2=A0 =C2=A0 my=C2=A0@b =3D (1, |@b, 2=
,=C2=A0@b, 3);<br>
&gt;=C2=A0 =C2=A0 =C2=A0 &gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0 &gt; gives you (1, &#39;a&#39;, &#39;b&#39;, &#39;=
c&#39;, 2, (&#39;a&#39;, &#39;b&#39;, &#39;c&#39;), 3). This often<br>
&gt;=C2=A0 =C2=A0 =C2=A0matters<br>
&gt;=C2=A0 =C2=A0 =C2=A0 &gt; in parameter lists, if you want one of the pa=
rameters to be the list<br>
&gt;=C2=A0 =C2=A0 =C2=A0 &gt; itself instead of it being spread across mult=
iple parameters. In<br>
&gt;=C2=A0 =C2=A0 =C2=A0Perl 5<br>
&gt;=C2=A0 =C2=A0 =C2=A0 &gt; you had to say \@b to pass a ref to the list =
instead, and the sub<br>
&gt;=C2=A0 =C2=A0 =C2=A0had to<br>
&gt;=C2=A0 =C2=A0 =C2=A0 &gt; know it was getting a scalar containing an ar=
rayref and needed to<br>
&gt;=C2=A0 =C2=A0 =C2=A0 &gt; dereference it (if you don&#39;t know, don&#3=
9;t ask; it&#39;s ugly).<br>
&gt; <br>
&gt;=C2=A0 =C2=A0 =C2=A0Am I correct in my assumption?<br>
&gt; <br>
&gt;=C2=A0 =C2=A0 =C2=A0A little off the question, but how do I address som=
ething<br>
&gt;=C2=A0 =C2=A0 =C2=A0inside a nested array?<br>
&gt; <br>
&gt;=C2=A0 =C2=A0 =C2=A0In the following, how do I get at the &quot;b&quot;=
<br>
&gt; <br>
&gt; <br>
&gt;=C2=A0 =C2=A0 =C2=A0$ p6 &#39;my @x=3D&lt;a b c&gt;; my @y=3D&lt;1 2 @x=
 3 4&gt;; say @y; dd @y;&#39;<br>
&gt; <br>
&gt;=C2=A0 =C2=A0 =C2=A0[1 2 @x 3 4]<br>
&gt; <br>
&gt;=C2=A0 =C2=A0 =C2=A0Array @y =3D [IntStr.new(1, &quot;1&quot;), IntStr.=
new(2, &quot;2&quot;), &quot;\@x&quot;,<br>
&gt;=C2=A0 =C2=A0 =C2=A0IntStr.new(3,<br>
&gt;=C2=A0 =C2=A0 =C2=A0&quot;3&quot;), IntStr.new(4, &quot;4&quot;)]<br>
&gt; <br>
&gt;=C2=A0 =C2=A0 =C2=A0Also, how do I flatten @y above?<br>
&gt; <br>
&gt;=C2=A0 =C2=A0 =C2=A0Thank you for the help!<br>
&gt;=C2=A0 =C2=A0 =C2=A0-T<br>
&gt; <br>
&gt; <br>
&gt; <br>
&gt; -- <br>
&gt; brandon s allbery kf8nh<br>
&gt; <a href=3D"mailto:allbery.b@gmail.com" target=3D"_blank">allbery.b@gma=
il.com</a> &lt;mailto:<a href=3D"mailto:allbery.b@gmail.com" target=3D"_bla=
nk">allbery.b@gmail.com</a>&gt;<br>
<br>
<br>
-- <br>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
Computers are like air conditioners.<br>
They malfunction when you open windows<br>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
</blockquote></div><br clear=3D"all"><div><br></div>-- <br><div dir=3D"ltr"=
 class=3D"gmail_signature" data-smartmail=3D"gmail_signature"><div dir=3D"l=
tr"><div><div dir=3D"ltr"><div>brandon s allbery kf8nh</div><div><a href=3D=
"mailto:allbery.b@gmail.com" target=3D"_blank">allbery.b@gmail.com</a></div=
></div></div></div></div>

--000000000000e5639f0577874860--
0
allbery
10/6/2018 3:49:58 AM
--0000000000004b347f05778b919e
Content-Type: text/plain; charset="UTF-8"

Posted as an issue to the perl6/docs repo
https://github.com/perl6/doc/issues/2360

Just in case anyone wants to clarify...

Cheers

JJ

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

<div dir=3D"ltr"><div><div dir=3D"ltr">Posted as an issue to the perl6/docs=
 repo <a href=3D"https://github.com/perl6/doc/issues/2360">https://github.c=
om/perl6/doc/issues/2360</a><br></div><br></div><div>Just in case anyone wa=
nts to clarify...</div><div><br></div><div>Cheers</div><div><br></div><div>=
JJ<br></div></div>

--0000000000004b347f05778b919e--
0
jjmerelo
10/6/2018 8:56:31 AM
On 10/5/18 8:49 PM, Brandon Allbery wrote:
> Turns out I misspoke anyway; << >> isn't enough by itself.
>=20
> $ p6 'my @x=3D<a b c>; my @y=3D<<1 2 @x 3 4>>; say @y; dd @y;'
>=20
> @y will contain (1, 2, '@x', 3, 4). (Actually, the numbers will be=20
> things that are simultaneously numbers and strings, showing up as=20
> IntStr.new(1, '1') and such.) '@x' is a two-character string, not the=20
> list=C2=A0@x or its contents.
>=20
>  =C2=A0 =C2=A0 pyanfar Z$ 6 'my @x =3D <a b c>; my @y =3D <<1 2 @x[] 3 =
4>>; dd @y'
>  =C2=A0 =C2=A0 Array @y =3D [IntStr.new(1, "1"), IntStr.new(2, "2"), "a=
", "b", "c",=20
> IntStr.new(3, "3"), IntStr.new(4, "4")]
>=20
> Which flattens because it's interpolating values, since quoting=20
> constructs produce string-like things or lists of string-like things=20
> (role Stringy), not lists of lists. If you want a list of lists, you ar=
e=20
> better off just using lists directly, not the quoting constructs that=20
> are intended to give you lists of strings. This is similar to Perl 5,=20
> where qw() also doesn't expand variables:
>=20
>  =C2=A0 =C2=A0 pyanfar Z$ perl -MData::Dumper -E 'my @x =3D qw(a b c); =
my @y =3D qw(1=20
> @x 2); say Dumper(\@y)'
>  =C2=A0 =C2=A0 $VAR1 =3D [
>  =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 '1',
>  =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 '@x',
>  =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 '2'
>  =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ];
>=20
>=20
> On Fri, Oct 5, 2018 at 11:27 PM ToddAndMargo via perl6-users=20
> <perl6-users@perl.org <mailto:perl6-users@perl.org>> wrote:
>=20
>     On 10/5/18 6:28 PM, Brandon Allbery wrote:
>      > You can't with that, because < ... > acts like single quotes;
>     '@x' there
>      > is a string literal, not the list @x. If you use << ... >> then
>     it act
>      > like double quotes, and will use the list instead.
>=20
>     I am sorry.=C2=A0 With the top posting, I can't tell
>     what you are talking about.=C2=A0 I also can't tell which
>     of the three question I asked that you are
>     answering
>=20
>     :'(
>=20
>      >
>      > On Fri, Oct 5, 2018 at 9:23 PM ToddAndMargo via perl6-users
>      > <perl6-users@perl.org <mailto:perl6-users@perl.org>
>     <mailto:perl6-users@perl.org <mailto:perl6-users@perl.org>>> wrote:=

>      >
>      >=C2=A0 =C2=A0 =C2=A0On 10/5/18 6:09 PM, Brandon Allbery wrote:
>      >=C2=A0 =C2=A0 =C2=A0 > That's where the | comes in. If you say
>      >=C2=A0 =C2=A0 =C2=A0 >
>      >=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 my=C2=A0@b =3D (1, |@a=
, 2);
>      >=C2=A0 =C2=A0 =C2=A0 >
>      >=C2=A0 =C2=A0 =C2=A0 > then you get (1, 'a', 'b', 'c', 2) like in=
 Perl 5. But you can
>      >=C2=A0 =C2=A0 =C2=A0specify
>      >=C2=A0 =C2=A0 =C2=A0 > what gets flattened, so you can choose to =
flatten some
>     arrays but
>      >=C2=A0 =C2=A0 =C2=A0not
>      >=C2=A0 =C2=A0 =C2=A0 > others if you need to for some reason:
>      >=C2=A0 =C2=A0 =C2=A0 >
>      >=C2=A0 =C2=A0 =C2=A0 >=C2=A0 =C2=A0 =C2=A0 my=C2=A0@b =3D (1, |@b=
, 2,=C2=A0@b, 3);
>      >=C2=A0 =C2=A0 =C2=A0 >
>      >=C2=A0 =C2=A0 =C2=A0 > gives you (1, 'a', 'b', 'c', 2, ('a', 'b',=
 'c'), 3). This
>     often
>      >=C2=A0 =C2=A0 =C2=A0matters
>      >=C2=A0 =C2=A0 =C2=A0 > in parameter lists, if you want one of the=
 parameters to
>     be the list
>      >=C2=A0 =C2=A0 =C2=A0 > itself instead of it being spread across m=
ultiple
>     parameters. In
>      >=C2=A0 =C2=A0 =C2=A0Perl 5
>      >=C2=A0 =C2=A0 =C2=A0 > you had to say \@b to pass a ref to the li=
st instead, and
>     the sub
>      >=C2=A0 =C2=A0 =C2=A0had to
>      >=C2=A0 =C2=A0 =C2=A0 > know it was getting a scalar containing an=
 arrayref and
>     needed to
>      >=C2=A0 =C2=A0 =C2=A0 > dereference it (if you don't know, don't a=
sk; it's ugly).
>      >
>      >=C2=A0 =C2=A0 =C2=A0Am I correct in my assumption?
>      >
>      >=C2=A0 =C2=A0 =C2=A0A little off the question, but how do I addre=
ss something
>      >=C2=A0 =C2=A0 =C2=A0inside a nested array?
>      >
>      >=C2=A0 =C2=A0 =C2=A0In the following, how do I get at the "b"
>      >
>      >
>      >=C2=A0 =C2=A0 =C2=A0$ p6 'my @x=3D<a b c>; my @y=3D<1 2 @x 3 4>; =
say @y; dd @y;'
>      >
>      >=C2=A0 =C2=A0 =C2=A0[1 2 @x 3 4]
>      >
>      >=C2=A0 =C2=A0 =C2=A0Array @y =3D [IntStr.new(1, "1"), IntStr.new(=
2, "2"), "\@x",
>      >=C2=A0 =C2=A0 =C2=A0IntStr.new(3,
>      >=C2=A0 =C2=A0 =C2=A0"3"), IntStr.new(4, "4")]
>      >
>      >=C2=A0 =C2=A0 =C2=A0Also, how do I flatten @y above?
>      >
>      >=C2=A0 =C2=A0 =C2=A0Thank you for the help!
>      >=C2=A0 =C2=A0 =C2=A0-T
>      >
>      >
>      >
>      > --
>      > brandon s allbery kf8nh
>      > allbery.b@gmail.com <mailto:allbery.b@gmail.com>
>     <mailto:allbery.b@gmail.com <mailto:allbery.b@gmail.com>>

Hi Brandon,

I didn't think you'd ever expect to hear these words out of
my mouth, but I understand now.  Thank you!

$ p6 'my @x=3D<a b c>; my @y=3D<<1 2 @x[] 3 4>>; dd @y; say @y; for @y.kv=
 ->=20
$i,$j {say "Index=3D$i  Value=3D$j"};'

Array @y =3D [IntStr.new(1, "1"), IntStr.new(2, "2"), "a", "b", "c",=20
IntStr.new(3, "3"), IntStr.new(4, "4")]

[1 2 a b c 3 4]

Index=3D0  Value=3D1
Index=3D1  Value=3D2
Index=3D2  Value=3Da
Index=3D3  Value=3Db
Index=3D4  Value=3Dc
Index=3D5  Value=3D3
Index=3D6  Value=3D4


By the way, in P5, where I had to address elements of an array
with $[] use to DRIVE ME INSANE!

-T
0
perl6
10/6/2018 10:22:47 AM
On 10/6/18 1:56 AM, JJ Merelo wrote:
> Posted as an issue to the perl6/docs repo 
> https://github.com/perl6/doc/issues/2360
> 
> Just in case anyone wants to clarify...
> 
> Cheers
> 
> JJ

You are the man!
0
perl6
10/6/2018 10:24:14 AM
On 10/5/18 3:15 PM, Ralph Mellor wrote:
> Well I guess my first way of explaining it was a complete bust. :)
>=20
> It's not going to be worth me discussing your reply to my first attempt=
=2E
>=20
> List context means that something appears in the context of a list.
>=20
> For example, given the list of characters EEEEAEEEE, A appears
> in the context of a list of 9 characters.
>=20
> Flattening a list means creating a new list from an old list such
> that any scalar items in the old list are just copied into the new
> list and any inner list items in the old list are copied one element
> at a time into the new list.
>=20
> In code:
>=20
>  >=C2=A0 1 ,2, [3,4], 5, 6
> ( 1 2 [3 4] 5 6)
>=20
> shows that the resulting list is 5 elements, with the third being
> the single list [3,4] because it does *not* flatten in list context.
>=20
> In contrast, in:
>=20
>  >=C2=A0 1 ,2, |[3,4], 5, 6
> ( 1 2 3 4 5 6)
>=20
> we get 6 elements instead because the `|` makes its right hand
> side argument flatten into the list context in which it appears.
>=20
> I won't be surprised to hear that's left you more confused, not less.
>=20
> If so it'll be time for someone else to try and explain it. :)
>=20
> --
> raiph

Hi Raiph,

I understand now.  Thank you!

-T
0
perl6
10/6/2018 10:25:52 AM
Reply: