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>
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>
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.
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.
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