<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><br></div><div id="AppleMailSignature"><blockquote type="cite" __apple_fixed_attribute="true"><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);"><br>On 22 Feb 2017, at 08:05, Jacob Bandes-Storch via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br><br></span></font></blockquote><blockquote type="cite"><div dir="ltr"><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">Evolutioniers,</span></font></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);"><br></span></font></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);"><b>Compound name syntax</b> — 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.</span></font></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);"><br></span></font></div><div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);"> func foo() {} // no compound syntax for this one :(</span></font></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);"> func foo(_ bar: Int) {} // foo(_:)</span></font></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);"> func foo(bar: Int) {} // foo(bar:)</span></font></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);"> func foo(bar: String, baz: Double) {} // foo(bar:baz:)</span></font></div></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);"><br></span></font></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">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".</span></font></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);"><br></span></font></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">I filed <a href="https://bugs.swift.org/browse/SR-3550">SR-3550</a> 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.</span></font></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);"><br></span></font></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">To kick off the discussion, <b>I'd like to propose foo(:) for nullary functions.</b></span></font></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);"><br></span></font></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">Advantages:</span></font></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">- the colon marks a clear similarity to the foo(bar:) form when argument labels are present.</span></font></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">- cutely parallels the empty dictionary literal, [:].</span></font></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);"><br></span></font></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">Disadvantages:</span></font></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">- violates intuition about one-colon-per-argument.</span></font></div></div></blockquote><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="background-color: rgba(255, 255, 255, 0);">This is a big disadvantage for me and will potentially be very surprising for newcomers.</span></div><span style="background-color: rgba(255, 255, 255, 0);"><br></span><blockquote type="cite"><div dir="ltr"><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">- the parallel between #selector(foo(:))and @selector(foo) is not quite as obvious as between #selector(foo(_:))and @selector(foo:).</span></font></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);"><br></span></font></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);"><br></span></font></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">For the sake of discussion, another option would be <b>foo(_)</b>. This was my original choice, and I like that the number of colons matches the number of parameters. However, it's a little less obvious as a function reference. It would preclude _ from acting as an actual identifier, and might conflict with pattern-matching syntax (although it appears functions can't be compared with ~= anyway).</span></font></div></div></blockquote><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="background-color: rgba(255, 255, 255, 0);">This is my favorite syntax so far.</span></div><span style="background-color: rgba(255, 255, 255, 0);"><br></span><blockquote type="cite"><div dir="ltr"><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">Looking forward to everyone's bikeshed color ideas,<br clear="all"></span></font><div><div class="gmail_signature"><div dir="ltr"><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">Jacob<br></span></font></div></div></div></div></blockquote><blockquote type="cite"><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">_______________________________________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span></font></blockquote></div></body></html>