Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.

assigning to named parameters

Skip to first unread message

Aaron Sherman

Sep 14, 2006, 7:36:31 AM9/14/06
I was looking over an example of named parameter passing:

foo(:a<1>, :b<2>)

And had the thought that we might be able to get away with treating
named parameters as lvalues, making the above:

foo(:a=1, :b=2)

Would this be unreasonable? Does it break anything else? I'm not sure
that subscripting-like notation would be a bad thing to have, but if we
could "assign" an arbitrary expression to a name parameter, I think
subroutine and method calls would be a heck of a lot more like their own
documentation. It also makes things like this easier to write:


If you use this syntax for something that would be auto-quoted, it's one
extra character:


but later edits are less complicated:


Thoughts? Is it too late?

Lanny Ripple

Sep 15, 2006, 4:57:37 PM9/15/06
It's not really lvalue syntax for named parameters but just pair
notation. See L<S02/Literals/generalized adverbial form of Pair

foo(:a<1>, :b<2>);


foo( a => '1', b => '2' );


If you want to assign an arbitrary expression to a named parameter

my $user = "ajs";
add_user( username => $user );

then you would use the above or

add_user( :username($user) );


If you look closely a lot of Perl 6 syntax is just shortcuts on
Perl 5 syntax.

It's probably never too late with a language explicitly designed
to be mutable but if I had to guess you'll have to code it up as
a new grammar rule and include it yourself via a pragma or other
explicit declaration.


0 new messages