mauke / Function-Parameters

Function::Parameters - define functions and methods with parameter lists ("subroutine signatures")
https://metacpan.org/pod/Function::Parameters
18 stars 19 forks source link

Can't have slurpy array with named parameters #39

Closed srchulo closed 1 year ago

srchulo commented 4 years ago

Using a slurpy array with named parameters generates this warning:

Odd number of paired arguments for method my_method at test.pl line 10.

method my_method (:$id, @args) {

}

It would be nice if an array could be slurpy after named parameters.

mauke commented 1 year ago

That doesn't really make sense because named parameters don't "stop". Once the argument list reaches the named parts, it's all names all the way:

$object->my_method(foo => 1, bar => 2, id => "x");

This would still set $id = "x" and @args = (foo => 1, bar => 2).

And I can't just stop parsing for name/value pairs after seeing id => "x" because the following is also supported:

$object->my_method(foo => 1, bar => 2, id => "x", quux => "asdf", id => "y", quux => 3);

This sets $id = "y" and @args = (foo => 1, bar => 2, quux => 3) (or some permutation thereof).

Essentially, once you start using named parameters, hash semantics kick in for the rest of the argument list: Arguments are treated as key/value pairs; keys are stringified; earlier values are overwritten by later values with the same keys.

Given the above, I don't see a way to make your request work in a sensible way