> -----Original Message-----
> From: Juerd [mailto:[EMAIL PROTECTED]
> Sent: Saturday, December 24, 2005 7:26 PM
> To: perl6-language@perl.org
> Subject: binding arguments
> 
> Merry Christmas to you all!
> 
> We use => for pairs, but also for something very different: named
> argument binding. Yes, pairs are used for that, but that introduces
> problems. The most important problem, that pairs sometimes have to be
> passed, and sometimes have to be named arguments, is fixed with a hack
> that to me, just doesn't feel right: if the pair is literal and not
> inside grouping parens, it's a named argument. Otherwise, it's a pair.
> Especially with the function of the () glyphs being different between
> with and without whitespace after the subname, this can be very
> confusing.
> 
> I'd like pairs and argument binding to be two different things. With
> different syntaxes.
> 
> The next thing I thought was: hey, argument *passing* is actually
> *binding* to variables in the sub, so why not use the := operator? That
> works very well, because binding as an expression makes no sense anyway,
> it being a language thing. And luckily, named arguments are also a
> language thing, so that works out:
> 
>     foo(
>         named_arg := $value,
>         other_arg := $value,
>     );
> 

   The only problem I'd have with this is what if there already exists a
variable with the same name as the named argument?

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?
say $named_arg; #Must print 1, not 2

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

foo($named_arg <- $value);
foo($value -> $named_arg);

Which one of these two is better depends on whether you think the parameter
or the argument being bound to it is more important.  


Joe Gottman


Reply via email to