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

assigning to named parameters

0 views
Skip to first unread message

Aaron Sherman

unread,
Sep 14, 2006, 7:36:31 AM9/14/06
to perl6-l...@perl.org
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:

arc(:radians=pi);

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

add_user(:username="ajs");

but later edits are less complicated:

add_user(:username="ajs-1");

Thoughts? Is it too late?

Lanny Ripple

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

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

is

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.

-ljr

0 new messages