Jonathan Lang wrote:
Larry Wall wrote:
You don't need to use | to store a capture any more than you need @ to
store an array. Just as
$x = @b;
@$x;
gives you the original array,
Huh. I'm not used to this happening. So what would the following
code do, and why?
my @b = ('foo', 'bar');
my $x = @b;
say $x;
@b gets a list shoved into it
$x gets the array @b shoved into it
The array @b gets printed.
Arrays in a scalar context in Perl6 auto-capture themselves and the
scalar becomes a reference to the array (or hash, or even capture, for
that matter).
At a higher level, think of it this way: all data types are objects.
Assigning an array into a scalar is just a change in notation.
likewise
$x = [EMAIL PROTECTED];
@$a;
gives you the original array as well.
Err... don't you mean '@$x' instead of '@$a'?
Yes, he does.
: >we currently don't allow assignment to a capture, only binding.
:
: IOW, if you want someone to be able to say '$|x' and get '$a' as a
: result, you'd have to say '|x := \$a' (or perhaps '$|x := $a') instead
: of '|x = \$a'. Right?
Yes. That's how it's currently specced, anyway. (The \ is probably
required, or it'll try to bind to the contents of $a instead.)
???
IMHO most of the confusion here goes away if capture variables ONLY
store parameter-list-like captures, and any other kind of capture
should, IMHO, permute itself into such a structure if you try to store
it into one. That way, their use is carefully constrained to the places
where Perl 6 can't already do the job.