[swift-evolution] Pitch: Compound name `foo(:)` for nullary functions

Derrick Ho wh1pch81n at gmail.com
Thu Feb 23 08:25:55 CST 2017


The back tick option is interesting. Back tick means "don't treat this as
an expression" which allows us to use keywords in certain areas but have
them. Act as something that isn't a keyword.

let f = `foo()`

However looking at it like this it almost looks like a string.
On Thu, Feb 23, 2017 at 9:16 AM Ben Rimmington via swift-evolution <
swift-evolution at swift.org> wrote:

>
> On 22 Feb 2017, at 07:05, Jacob Bandes-Storch wrote:
>
> *Compound name syntax* — foo(_:), foo(bar:), foo(bar:baz:) — is used to
> disambiguate references to functions. (You might've used it inside a
> #selector expression.) But there's currently no compound name for a
> function with no arguments.
>
>     func foo() {}  // no compound syntax for this one :(
>     func foo(_ bar: Int) {}  // foo(_:)
>     func foo(bar: Int) {}  // foo(bar:)
>     func foo(bar: String, baz: Double) {}  // foo(bar:baz:)
>
> Given these four functions, only the first one has no compound name
> syntax. And the simple reference "let myfn = foo" is ambiguous because it
> could refer to any of the four. A workaround is to specify a contextual
> type, e.g. "let myfn = foo as () -> Void".
>
> I filed SR-3550 <https://bugs.swift.org/browse/SR-3550> for this a while
> ago, and there was some discussion in JIRA about it. I'd like to continue
> exploring solutions here and then write up a formal proposal.
>
>
> Would the following be an option?
>
> foo()  // Function call expression.
> `foo()` // Function reference (using backticks).
>
> -- Ben
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170223/e738abf4/attachment.html>


More information about the swift-evolution mailing list