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

RFC: outplace argument _ #402

Closed
timotheecour opened this issue Nov 30, 2020 · 1 comment
Closed

RFC: outplace argument _ #402

timotheecour opened this issue Nov 30, 2020 · 1 comment

Comments

@timotheecour
Copy link
Owner

timotheecour commented Nov 30, 2020

proposal

Support the outplace argument _, for the common case of sugar.dup where the outplace argument is assumed to be initialized to its default value for its (inferred) type.

Example

proc merge[T](result: var seq[T], x, y: openArray[T]) = ...
let x = [1,3]
let y = [2,5]
let a = merge(_, x, y)
let a2 = _.merge(x,y) # also works

# same as:
var a: seq[int]
merge(a, x, y)
a

implementation

  • requires compiler support.
  • in sigmatch, the arguments are implicitly reordered so that _ is matched last, at which point all generic parameters must be bound, or a sigmatch error occurs.

links

@timotheecour
Copy link
Owner Author

=> nim-lang/RFCs#292

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant