[swift-evolution] [Pitch] Allow trailing argument labels

Robert Bennett rltbennett at icloud.com
Thu Feb 23 22:27:42 CST 2017


Hi everyone, this is my first post, hopefully I get the formatting and everything right...
> why not just require a leading dot, like an enum, rather than a colon?
> less syntax to learn, and it still eliminates the extra type.
I think this could lead to ambiguity if the trailing argument label was also an enum case, and there was a function signature whose last argument type was that enum. E.g.,
enum E {
	case trailing
}
func foo(_ i: Int, trailing: E) {}
func foo(_ i: Int, trailing) {}

Now, which version of foo gets called by foo(1, .trailing)? It's a contrived example but demonstrates a real problem.
Since the dollar sign is so rarely used — correct me if I'm wrong, but its only current use is for positional closure arguments — I propose we use it for trailing arguments. The fact that it seems out of place in a function context makes its intention clear — unlike, say, a colon which definitely "belongs" within a function's parentheses, or a period which can go just about anywhere.
The syntax I propose would be the following:
// Define
func foo(_ i: Int, $trailing) {}
// Call
foo(1, $trailing)

It's not exactly pretty, but it's certainly unambiguous and makes the intention clear.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170223/4591661b/attachment.html>


More information about the swift-evolution mailing list