Joe Gottman skribis 2005-12-24 19:59 (-0500):
> sub foo($named_arg) {say $named_arg;}
> my $named_arg = 1;
> my $value = 2;
> foo($named_arg := $value); #Does this bind my $named_arg to $value?

Because the := is used in .(), it is not binding in the current scope,
but in the called subroutine. In foo($bar := $baz), $bar is always the
name of the argument, and if "foo" doesn't have that name, and doesn't
have anything to slurp unknown named arguments, things fail.

> To avoid this, perhaps we can use <- or -> instead?

The problem about this is that it has to be exactly the other way around
than pairs, which may make the difference a bit too large.

Besides that, it is a big problem for people who don't like to use
whitespace: foo < -5, they write as foo<-5.

I do not think there is any need to have different symbols for direct
binding and named argument binding, because I can't think of any case
where using direct binding in an expression has any benefit. Copying in
expressions is usually done because the copy is modified, but that
argument doesn't work for aliasing.

However, := is a weird symbol, the more I think about it. It has nothing
to do with colons or assignment. Colons are used for pairs, assignment
for copying values. It looks like +=, but doesn't quite work like it.
And ::= seems entirely arbitrarily chosen. But I may be wrong.


Reply via email to