Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Dumb list-flattening question.

6 views
Skip to first unread message

Mark J. Reed

unread,
Sep 21, 2006, 9:53:34 AM9/21/06
to perl6-l...@perl.org
Ok, I dkimmed through the synopses again and didn't see this offhand.

If I have two arrays @a and @b and I wish to create a two-element list
out of them - a la Perl5 (\@a, \@b) - what's the correct way to do
that in Perl6? If it's still (\@a, \@b), then what do we call what
the \ is doing there, now that references are supposed to be a
behind-the-scenes automagical thing?

--
Mark J. Reed <mark...@mail.com>

Juerd

unread,
Sep 21, 2006, 10:20:59 AM9/21/06
to perl6-l...@perl.org
Mark J. Reed skribis 2006-09-21 9:53 (-0400):

> If I have two arrays @a and @b and I wish to create a two-element list
> out of them - a la Perl5 (\@a, \@b) - what's the correct way to do
> that in Perl6? If it's still (\@a, \@b), then what do we call what
> the \ is doing there, now that references are supposed to be a
> behind-the-scenes automagical thing?

They're captures.

I personally wouldn't mind unary $, to supplement unary @ and %.
--
korajn salutojn,

juerd waalboer: perl hacker <ju...@juerd.nl> <http://juerd.nl/sig>
convolution: ict solutions and consultancy <sa...@convolution.nl>

Aaron Sherman

unread,
Sep 21, 2006, 10:54:00 AM9/21/06
to Mark J. Reed, perl6-l...@perl.org

To expand on the previous answer, unary backslash as described in S03
captures its argument and various representations can be extracted. In
this case, you are capturing an array, and creating a list of arrays.
This is done by reference, we presume, but that detail is not available
to the programmer the way it was in P5.

Other forms of capture:

\$var; # Capture a scalar
\%var; # Capture a hash
\(...); # Capture parameters

\\$foo (as in Perl 5) is not a "capture to a capture", it simply acts
like \$foo.

Mark J. Reed

unread,
Sep 21, 2006, 11:22:51 AM9/21/06
to Aaron Sherman, perl6-l...@perl.org
> Mark J. Reed wrote:
> > Ok, I dkimmed through the synopses again and didn't see this offhand.

That's what I get for dkimming instead of reading. Or even skimming.

OK, so "Capture objects fill the ecological niche of references in
Perl 6." Got it. Perhaps we should also mention the use of Captures
to prevent list flattening somewhere in S09.

So now we have | as the "all of the above" dereferencer. I like the
mnemonic association with junctions, since |$x is logically similar to
($$x|@$x|%$x).

I dislike adding yet more whitespace-resolved ambiguity to the grammar, though.

Mark Stosberg

unread,
Sep 21, 2006, 9:15:33 PM9/21/06
to perl6-l...@perl.org

I think it's a good question, considering this is worked for me in Perl 6:

my @c = (\@a, \@b);

I'm not sure how to reconcile that with the spec I found for "\":

"The unary backslash operator captures its arguments, and returns an
object representing those arguments."

Mark


0 new messages