Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow named parameters with literal values in signatures #5310

Open
p6rt opened this issue May 10, 2016 · 3 comments
Open

Allow named parameters with literal values in signatures #5310

p6rt opened this issue May 10, 2016 · 3 comments
Labels
RFC Request For Comments

Comments

@p6rt
Copy link

p6rt commented May 10, 2016

Migrated from rt.perl.org#128108 (status was 'open')

Searchable as RT128108$

@p6rt
Copy link
Author

p6rt commented May 10, 2016

From @dwarring

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).

@p6rt
Copy link
Author

p6rt commented May 10, 2016

@smls - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Jun 21, 2016

From @dwarring

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​:

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).

@p6rt p6rt added the RFC Request For Comments label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFC Request For Comments
Projects
None yet
Development

No branches or pull requests

1 participant