<div dir="ltr">+1<div><br></div><div>I prefer <font face="monospace, monospace">foo(:)</font> because it matches with empty dictional literal <font face="monospace, monospace">[:]</font>.</div><div><br></div><div>Also, <font face="monospace, monospace">foo(_)</font> potentially introduce a confusion.</div><div>Remember that this syntax can be appear in a pattern.</div><div><br></div><div>```</div><div><div><div><font face="monospace, monospace">struct S {</font></div><div><font face="monospace, monospace"> let val: Int</font></div><div><font face="monospace, monospace">}</font></div><div><font face="monospace, monospace">func newS() -> S { return S(val: 0) }</font></div><div><font face="monospace, monospace">func newS(_ val: Int) -> S { return S(val: val) }</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">func ~= (pat: () -> S, obj: S) -> Bool { return pat().val == obj.val }</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">let obj = S(val: 0)</font></div><div><font face="monospace, monospace">switch obj {</font></div><div><font face="monospace, monospace">case newS(_): // Is this a pattern???</font></div><div><font face="monospace, monospace"> break</font></div><div><font face="monospace, monospace">default:</font></div><div><font face="monospace, monospace"> break</font></div></div></div><div><font face="monospace, monospace">}</font></div><div>```</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2017-02-22 16:05 GMT+09:00 Jacob Bandes-Storch via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Evolutioniers,</div><div><br></div><div><b>Compound name syntax</b> — <font face="monospace, monospace">foo(_:)</font>, <font face="monospace, monospace">foo(bar:)</font>, <font face="monospace, monospace">foo(bar:baz:)</font> — 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.</div><div><br></div><div><div><font face="monospace, monospace"> func foo() {} // no compound syntax for this one :(</font></div><div><font face="monospace, monospace"> func foo(_ bar: Int) {} // foo(_:)</font></div><div><font face="monospace, monospace"> func foo(bar: Int) {} // foo(bar:)</font></div><div><font face="monospace, monospace"> func foo(bar: String, baz: Double) {} // foo(bar:baz:)</font></div></div><div><br></div><div>Given these four functions, only the first one has no compound name syntax. And the simple reference "<font face="monospace, monospace">let myfn = foo</font>" is ambiguous because it could refer to any of the four. A workaround is to specify a contextual type, e.g. "<font face="monospace, monospace">let myfn = foo as () -> Void</font>".</div><div><br></div><div>I filed <a href="https://bugs.swift.org/browse/SR-3550" target="_blank">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.</div><div><br></div><div>To kick off the discussion, <b>I'd like to propose <font face="monospace, monospace">foo(:)</font> for nullary functions.</b></div><div><br></div><div>Advantages:</div><div>- the colon marks a clear similarity to the <font face="monospace, monospace">foo(bar:)</font> form when argument labels are present.</div><div>- cutely parallels the empty dictionary literal, <font face="monospace, monospace">[:]</font>.</div><div><br></div><div>Disadvantages:</div><div>- violates intuition about one-colon-per-argument.</div><div>- the parallel between <font face="monospace, monospace">#selector(foo(:))</font> and <font face="monospace, monospace">@selector(foo)</font> is not quite as obvious as between <font face="monospace, monospace">#selector(foo(_:))</font> and <font face="monospace, monospace">@selector(foo:)</font>.</div><div><br></div><div><br></div><div>For the sake of discussion, another option would be <font face="monospace, monospace"><b>foo(_)</b></font>. 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).</div><div><br></div><div><div><br></div><div>Looking forward to everyone's bikeshed color ideas,<br clear="all"><div><div class="m_938051620705225519gmail_signature"><div dir="ltr"><div>Jacob<br></div></div></div></div>
</div></div></div>
<br>______________________________<wbr>_________________<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" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br>
<br></blockquote></div><br></div>