Ingo Blechschmidt skribis 2005-09-09 11:59 (+0000):
> > > > \(@array,) is [ @array ], NOT map { \$_ } @array 
> > > I'm not sure of the []s, remember &postcirumfix:<[ ]> creates *new* 
> > > containers: 
> > That was the point. 
> > >     [EMAIL PROTECTED] = $bar; 
> > >     (@array,)[0] = $bar; 
> > AFAIK, these are the same thing, because the left side of [0] is in 
> > Array context, which is a scalar context, in which comma creates a new 
> > anonymous array ref. 
> To prevent misconceptions: You think that both 
>     [EMAIL PROTECTED]  = $bar;  # and 
>     (@array,)[0] = $bar; 
> change @array[0] to $bar, right? 

No, neither does.

[EMAIL PROTECTED] = $bar fills a new array with the elements of @array, and then
overwrites the first. The array is then discarded.

(@array,)[0] = $bar does the same, IIRC, because the LHS of .[0] is
object and thus scalar context, possibly specifically Array context, and
the comma operator then behaves as if it has [] around it: it creates an
anonymous array. Again, it's just the elements of @array that are used.

Now, (@array)[0] = $bar does assign to @array[0].

I think the comma operator in scalar context should not create arrays,
because that is wildly confusing for most people, and a dangerous trap
even for those who do grok it. We already have [] for creating anonymous
arrays, and here a second WTDI isn't buying us anything. Especially the
apparent similarity in the different (@array) and (@array,) is something
we should try to avoid.

>     (my $arrayref = [1,2,3])[1] = 42; 

[1, 42, 3]. With () for grouping, not lists, and [] working on
references as well as the original, you're assigning to $arrayref[1],
not the nonexistent second element of the nonexistent list.

>     sub *postcircumfix:<[ ]> ([EMAIL PROTECTED]) { 

Do postfix list operators exist in Perl 6? AFAIK, the only thing that
can create a list is list context, and I'm very unsure how anything that
can handle both a list and an item can be postfix.
    
> And, presuming that I've understood you correctly

Which I don't think you have.


Juerd
-- 
http://convolution.nl/maak_juerd_blij.html
http://convolution.nl/make_juerd_happy.html 
http://convolution.nl/gajigu_juerd_n.html

Reply via email to