On Fri, Aug 19, 2005 at 08:39:24AM -0700, Larry Wall wrote:
: Actually, that's an argument that : is in a different class than the regex
: quantifiers, and required named should be
:
: sub bar (+$:key)
:
: as I speculated earlier. Maybe we just force that to bind to $key instead
: of $:key.
Which makes me wonder whether, in ordinary code (not sigs)
$:key
is short for
:key($key)
The idea being that it makes it really easy to pass delegate particular
pairs to subfunctions as long as you keep the names consistent. It'd
also make it drop-dead easy to write positional-to-named constructors:
method new ($proto: $a, $b, $c) {
...
return $proto.bless($:a, $:b, $:c);
}
instead of
method new ($proto: $a,$b,$c) {
...
return $proto.bless(:a($a), :b($b), :c($c));
}
I suppose if we pushed it we could even allow $:foo in adverbial position.
1 .. 100 $:by
But I wonder if people will think that
foo 1, 2, 3, @:foo
should interpolate @foo as a list of pairs rather than binding to the
'foo' argument. Likewise for %:bar. But those are still [EMAIL PROTECTED] and
*%bar, I suspect, and people can learn that the : twigil always means
rewrite. Hmm. That seems to indicate that the actual signature for
named parameters is
sub foo (:foo($foo))
and that
sub foo ($:foo)
is just shorthand for that. That would give us the ability to give the
variable a different name than the parameter. I like.
sub seek (:x($horizontal),:y($vertical))
On the other hand, it's now unclear whether you can call that as seek(1,2).
Needs to be allowed somehow.
Larry