Open timotheecour opened 3 years ago
I don't mean to delay or complicate anything, but thoughts on this?
proc merge[T](result: var seq[T], x, y: openArray[T]) = ...
let x = [1, 3]
let y = [2, 5]
merge(let a, x, y)
(let a2).merge(x,y) # torn on this one
proc fn[T](a: seq[T], b: var T) = ...
fn(@[1, 2], let a)
@[1, 2].fn(let a2)
I believe some other language does something like this but I forget
This RFC is stale because it has been open for 1095 days with no activity. Contribute a fix or comment on the issue, or it will be closed in 30 days.
proposal
Support the outplace argument placeholder
_
to convert an inplace algorithm into an outplace one for the common case where the outplace argument is assumed to be initialized to its default value for its (inferred) type.Example
Notes
the outplace argument can appear in any position, not just the 1st, as its position is given explicitly by
_
:sugar.dup
is still useful in the cases where you need a non-default value for the outplace argument, or when type inference wouldn't be possible, because the generic is only inferred from the outplace argument instead of other arguments.implementation
_
is matched last, at which point all generic parameters must be bound, or a sigmatch error occurs.links