Last active

Must named arguments bind to positional parameters?

  • Download Gist

Must named arguments bind to positional parameters?

tl;dr summary

S06 says that named arguments in Perl 6 can bind to positional parameters.

Please remove that bit.

What S06 says

According to S06:989,

Bindings happen in declaration order, not call order, so any default
may reliably depend on formal parameters to its left in the signature.
In other words, if the first parameter is C<$a>, it will bind to
a C<:a()> argument in preference to the first positional argument.

That is, if your subroutine looks like this:

sub foo($a, $b) { say $a, " ", $b }

Then this call

foo("OH", :a<HAI!>);

will print HAI! OH, not OH HAI!.

The important point isn't that arguments can be made in any order, but that because of this feature, the names of positional parameters become part of the public API of any exported routine.

The arguments against this feature

In decreasing order of perceived importance.

  • Since Perl 6 programmers (experienced and newbie alike) don't seem to realize the feature is there, this has a high probability of leading to "over-publishing" of APIs. That might not sound so bad until one realizes that a module author has committed not to change the names of any parameters in the module's exported routines.

  • It makes the binder more complicated. The default lookup would have to be by name (hash-like) rather than by position (array-like), and that's slower. S06 asserts (at S06:993) that performance can be regained by various optimizations. Such optimizations would further complicate the binder.

  • No-one uses the feature. To wit, the only examples of this feature that the undersigned have seen have been just that: examples. (The post chronicling the comes to mind.) Had the feature been very important and something that Perl 6 coders out there reached for regularly, the above objection about binder complexity and performance challenges would be comparatively weaker. As it stands now, that complexity is harder to motivate.


We argue that binding named arguments to positional parameters is a treacherous, unwanted, and needlessly complex feature. Please remove it.

Regards, Carl Mäsak and Jonathan Worthington

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.