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 06:03
Subject:
Re: (1,(2,3),4)[2]
Message ID:
20050525130258.GB31996@c4.convolution.nl
"TSa (Thomas SandlaƟ)" skribis 2005-05-25 13:53 (+0200):
> >>%a = ( a => 1, b => 2, c => 3 )  # @a = (1,2,3)
> >HASH = THREE PAIRS
> I look at it as &infix:{'='}:( Hash, List of Pair : --> Ref of Hash )
> and then try to understand how it behaves. BTW, I'm neither sure
> of the type of the second invocant parameter nor of the return type.
> Even the position of the : is contestable.

If assigning a ref to a hash uses the hashref's elements, then the same
is to be expected for an array. Because this behaviour is unwanted for
arrays (because you then can't assign a single arrayref anymore without
doubling the square brackets, communicating an entirely wrong thing),
hashes have to concede as well, even though %a = $href may not make
sense.

> And +[1,2,3] seems to mean &prefix:<+>:(Ref of Array: --> Num)
> while +(1,2,3) is &prefix:<+>:(List: --> Num). More interesting

The + forces scalar Num context. So it can probably be written as
something resembling

    sub &prefix:<+> (Num $foo) { $foo }

Prefix + doesn't take a list. If you use comma in scalar context, an
array reference is created. This makes +[] and +() practically equal,
but that doesn't mean [] and () are always exchangeable, or even that
they have anything to do with eachother. In +[], the [] make the
arrayref, while in +(), the comma does that. If you have +() without
comma, you don't have an arrayref, because () only groups.

> are the &infix:<,> inside

I recall having read something about , being "listfix", not infix. The
same would be true for Y and | and & and ^.


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