Skip Menu |
Report information
Id: 128108
Status: open
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: david.warring <david.warring [at] gmail.com>
Cc:
AdminCc:

Severity: (no value)
Tag: (no value)
Platform: (no value)
Patch Status: (no value)
VM: (no value)



Subject: Feature request - improvements to named parameter handling
Download (untitled) / with headers
text/plain 991b
Rakudo is pretty good at parsing literal arguments as positional parameters. For example: multi sub s(True) { 'case1' } # Bool $ where $_ multi sub s('fred') { 'case2' } # Str $ where 'fred' multi sub s(42) {'case3' } # Int $ where 42 for 1+1==2, 'fred', 42 -> $val { say s($val) } #case1 #case2 #case3 If I refactor the above from a positional to a named parameter, then I need to be a bit more explicit. Something like: multi sub s(Bool :$val! where $_) { '#case1' } multi sub s(Str :$val! where 'fred') { '#case2' } multi sub s(Numeric :$val! where 42) { '#case3' } for 1+1==2, 'fred', 42 -> $val { say s(:$val) } Can the handling of named arguments be improved to more like the positional case? I was hoping for something like: multi sub s(:val) { "#case1" } multi sub s(:val<fred>) { "#case2" } multi sub s(:val(42)) { "#case3" } Or something similar (None of these parse at the moment).
Download (untitled) / with headers
text/plain 1.1k
Another case, a false boolean value: multi sub s(False) { 'case4' } rfc for positional: muli sub s(:!val ) { 'case4' } # Bool $ where !$_ On Mon May 09 21:57:05 2016, david.warring wrote: Show quoted text
> Rakudo is pretty good at parsing literal arguments as positional > parameters. For example: > > multi sub s(True) { 'case1' } # Bool $ where $_ > multi sub s('fred') { 'case2' } # Str $ where 'fred' > multi sub s(42) {'case3' } # Int $ where 42 > > for 1+1==2, 'fred', 42 -> $val { > say s($val) > } > #case1 > #case2 > #case3 > > If I refactor the above from a positional to a named parameter, then I > need to be a bit more explicit. Something like: > > multi sub s(Bool :$val! where $_) { '#case1' } > multi sub s(Str :$val! where 'fred') { '#case2' } > multi sub s(Numeric :$val! where 42) { '#case3' } > > for 1+1==2, 'fred', 42 -> $val { > say s(:$val) > } > > Can the handling of named arguments be improved to more like the > positional case? I was hoping for something like: > > multi sub s(:val) { "#case1" } > multi sub s(:val<fred>) { "#case2" } > multi sub s(:val(42)) { "#case3" } > > Or something similar (None of these parse at the moment).


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org