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

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

Thread Previous | Thread Next
From:
=?ISO-8859-1?Q?=22TSa_=28Thomas_Sandla=DF=29=22?=
Date:
May 25, 2005 01:47
Subject:
Re: (1,(2,3),4)[2]
Message ID:
42943B88.6020800@orthogon.com
Juerd wrote:
> An array in scalar context evaluates to a reference to itself.
> 
> A hash in scalar context evaluates to a reference to itself.
> 
> An array in list context evaluates to a list of its elements.
> 
> A hash in list context evaluates to a list of its elements (as pairs).
> 
> Array context is a scalar context.

I have understand what you mean and how you---and other p6l'er---
derive +@a == 1 from @a = [1,2,3]. But allow me to regard this
as slightly inconsistent, asymmetric or some such.

Isn't hash context missing in the list above? How does

%a = ( a => 1, b => 2, c => 3 )  # @a = (1,2,3)

compare with

%b = { a => 1, b => 2, c => 3 }  # @b = [1,2,3]

Does that mean

3 == +%a == +%b
   == +{ a => 1, b => 2, c => c }
   == +( a => 1, b => 2, c => c )

holds and the access of the hash works as expected:

%a<a> == 1 == %b<a>  # and @a[0] == 1, but @b[0][0] == 1

What would actually be the equivalent syntax to @b?
Is it %b<><a> or %%b<a> or even (*%b)<a>?
It will hardly be %b{undef}<a>, though.
-- 
TSa (Thomas SandlaƟ)


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