[swift-evolution] Replace named returns with `out` parameters?
Anton Zhilin
antonyzhilin at gmail.com
Wed Dec 28 05:09:46 CST 2016
Some people on the list wondered, why we have moved from tuples in function
parameters, but multiple returns are still implemented using tuples? The
following code still compiles:
func position() -> (x: Int, y: Int) {
return (x: 0, y: 0)
}
let (y, x) = position()
(Maybe it’s a bad example, because naturally we’d use Point struct. Let’s
pretend those two parameters don’t make sense as a struct.)
What I want to discuss is if we should introduce out parameters *and* make
them the default for multiple returns for Swift 4. The syntax would look
like:
func position(x: out Int, y: out Int) {
x = 0
y = 0
}
var y
position(x: let x, y: y)
out arguments can be any patterns allowed on the left side of assignment,
including wildcard pattern and tuple destructuring pattern.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161228/1f59b2e8/attachment.html>
More information about the swift-evolution
mailing list