develooper Front page | perl.perl6.language | Postings from May 2005

Re: (1,(2,3),4)[2]

Thread Previous | Thread Next
From:
Juerd
Date:
May 25, 2005 10:54
Subject:
Re: (1,(2,3),4)[2]
Message ID:
20050525175404.GG31996@c4.convolution.nl
Mark Reed skribis 2005-05-25 10:49 (-0400):
> [1,2,3] is not an array or a list.  It is a reference to an anonymous array.
> It is not 3 values; it¹s 1 value, which happens to point to a list of size

Just for accuracy: it points to an array, which is still not a list in
our jargon.

> 3.  If you assign that to an array via something like @a = [1,2,3], I would
> expect at least a warning and possibly a compile-time error.
> 
>  If it does work, it probably gets translated into @a = ([1,2,3]), which

That's not a translation. Parens, when not postfix, serve only one
purpose: group to defeat precedence. $foo and ($foo) are always the same
thing, regardless of the $foo.

> I¹m not sure about +(@a[0]), but I¹m guessing it would == 3.

Because parens only group, and [0] here has tighter precedence than the
prefix + anyway, +(@a[0]) and +@a[0] are exactly the same. 

Because @a[0] is a reference to an array, that array is @{ @a[0] }. +@{
@a[0] } is also the same as +@a[0]. 

The numeric value of an array reference is the same as that of its
array.


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

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About