Although SE-0021
<https://github.com/apple/swift-evolution/blob/master/proposals/0021-generalized-naming.md>
has a good goal, I don't like the details due to the use of parenthesis:
I'd prefer to keep them limited to actual function calls.
But most of the time, it would be possible to avoid ambiguity and keep the
simpler syntax; this would be eliminated with you proposal, so I'm against it
(SE-0021 would only be needed in situations that can't be solved with the old
form).
> C1: Extend SE-0021
> <https://github.com/apple/swift-evolution/blob/master/proposals/0021-generalized-naming.md>
> by adding the underscore-in-parentheses syntax `foo(_)` to refer to the
> zero-argument function #1.
I don't think that's consistent with the other use cases of the underscore:
Afair, it never means "nothing", but always "there is something, but ignore it"
Additionally, I think it would be nice to have a clean way to avoid all
ambiguities when referring to a function be specifying all involved types, so
unless I didn't miss any downsides of using square brackets, my favorite would
look like
> func foo() // #1 Function named 'foo(_)' with type
> '() -> ()'.
let f = foo
> func foo(x: Int) -> Int // #2 Function named 'foo(x:)' with type
> 'Int -> Int' (not an overload).
let f = foo[x: Int]
> func foo(_ x: Int) -> Int // #3 Function named 'foo(_:)' with type
> 'Int -> Int'
let f = foo[Int]
> func foo(_ x: (Int, Int)) -> Int // #4 Function named 'foo(_:)' with type
> '(Int, Int) -> Int' (overload of #3).
let f = foo[(Int, Int)]
> func foo(x: Int, y: Int) -> Int // #5 Function named 'foo(x:y:)' with
> type '(Int, Int) -> Int'.
let f = foo[x: Int, y: Int]
> func foo(x: Int, y: Int) -> Bool // #6 Function named 'foo(x:y:)' with
> type '(Int, Int) -> Bool' (overload of #5).
let f = foo[x: Int, y: Int]
Ideally, it should be possible to specify the return type as well… but there
are so many syntax options for this, and I don't see a natural choice...
let f = foo:Bool[x: Int, y: Int]
let f = foo->Bool[x: Int, y: Int]
let f = foo[x: Int, y: Int; Bool]
let f = foo[x: Int, y: Int]->Bool
Tino
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution