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

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

Thread Previous | Thread Next
May 25, 2005 06:03
Re: (1,(2,3),4)[2]
Message ID:
"TSa (Thomas SandlaƟ)" skribis 2005-05-25 13:53 (+0200):
> >>%a = ( a => 1, b => 2, c => 3 )  # @a = (1,2,3)
> 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

> 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 ^.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About