These are
(my @a = 1), 2, 3;
(my $a = 1), 2, 3;
if I understand precedence correctly. (S03)
> my $a = *@a;
> my $a = *(1,2,3); # or is this a syntax error?
> my $a = *(list 1,2,3);
> my $a = *[1,2,3];
I hope this will emit some kind of too-many-arguments warning in
addition to assigning 1 to $a.
> and I have absolutely no clue about the following:
> my *$a = @a;
> my *$a = (1,2,3);
1, I hope. I think the * provides list context to the RHS as * in a
sub signature does to the arguments.
1 would be consistent with
my ($a) = @a;
in Perl 5
> my *$a = [1,2,3];
Arrayref.
(I don't like @a = []. It makes @a = ([]) be counter-intuitive (parens
only group for precedence), and @a = [[]] feels VERY weird. Besides
that, it makes @a = $b completely unpredictible if the type of $b is
unknown. If it's an arrayref, @a gets all its elements, but if it's a
normal value, @a gets only one element. That's a problem for general
purpose modules/subs. I guess they could all use @a = [$b], but I find
that ugly.)
Juerd
--
http://convolution.nl/maak_juerd_blij.html
http://convolution.nl/make_juerd_happy.html
http://convolution.nl/gajigu_juerd_n.html
if I understand correctly, all these are equivalents:
my @a = 1,2,3;
my @a = (1,2,3);
my @a = list 1,2,3;
my @a = [1,2,3]; # or does it make @a[0] = (1,2,3)?
and all these are too (they make $a a reference to an array):
my $a = 1,2,3;
my $a = (1,2,3);
my $a = list 1,2,3;
my $a = [1,2,3];
I'm not sure what the following do (assign 1 to $a maybe?):
my $a = *@a;
my $a = *(1,2,3); # or is this a syntax error?
my $a = *(list 1,2,3);
my $a = *[1,2,3];
and I have absolutely no clue about the following:
my *$a = @a;
my *$a = *@a;
my *$a = (1,2,3);
my *$a = [1,2,3];
thanks for any help.
cheers,
Aldo
right, sure. I vaguely remember something about comma instead of parens
being the list constructor, but maybe it was just in my fantasy.
and thanks for the other clarifications too.
to summarize, I think a decent implementation of "splat" should do the
following:
if the argument to unary * is...
a normal value force list context and cast to 1-elem list
a list nop
an array cast to list
an arrayref deref and cast to list
(I don't know if the use of "cast" is appropriate here. looks more like
AST munging...).
> (I don't like @a = []. It makes @a = ([]) be counter-intuitive (parens
> only group for precedence), and @a = [[]] feels VERY weird. Besides
> that, it makes @a = $b completely unpredictible if the type of $b is
> unknown. If it's an arrayref, @a gets all its elements, but if it's a
> normal value, @a gets only one element. That's a problem for general
> purpose modules/subs. I guess they could all use @a = [$b], but I find
> that ugly.)
in fact, S03 states:
"In list context, a scalar reference to an array does not flatten."
so I think @a = [1,2,3] should leave you with @a[0] = [1,2,3]. and you
should use one of:
@a = *$b;
@a = @$b;
@a = $b[];
to make @a get all the elements of the arrayref in $b.
cheers,
Aldo
Yes, @a[0] = [1,2,3];
> and I have absolutely no clue about the following:
>
> my *$a = @a;
> my *$a = *@a;
> my *$a = (1,2,3);
> my *$a = [1,2,3];
Those are all illegal. You need to use binding for those to make any
sense.
my *$a := @a; # $a = @a[0]
my *$a := *@a; # same
my *$a := (1,2,3); # $a = 1
my *$a := [1,2,3]; # $a = [1,2,3]
Luke
Nope, list assignment works just like in Perl 5. The motivation for
that in Perl 5 is that returned list values are treated as extensible,
and you don't want to break code when the module decides to return
a little more information. Think of how caller() has been extended
over the years. I'd like to keep that extensibility in Perl 6.
However, you can always get stricter argument counting by using binding
instead of list assignment, just like with regular parameter binding
for function calls. Hmm, next thing you know, someone's going to
suggest applying MMD to the left side of a binding. Ow.
Larry