<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Does this bridge over to referencing properties, such as using:<div class=""><br class=""></div><div class="">struct Bar {</div><div class=""> var counter:Int = 0</div><div class="">}</div><div class=""><br class=""></div><div class="">let fn3 = Bar#counter.get</div><div class=""><br class=""></div><div class="">-DW</div><div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 28, 2015, at 8:05 AM, T.J. Usiyan via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">Do things get any better if we combine the proposed changes and remove the bare case? Begin function reference with some symbol (# here but it doesn't matter), only use back tics to disambiguate keywords (which lines up with their current use) and remove the unadorned case to avoid ambiguity.<div class=""><br class=""></div><div class=""><div class="">```swift </div><div class="">class Foo {</div><div class=""><span class="" style="white-space: pre;">        </span>func doSomething() { }</div><div class=""><span class="" style="white-space: pre;">        </span>func doSomething(value: Int) { }</div><div class=""><span class="" style="white-space: pre;">        </span>func sub</div><div class="">}</div><div class=""><br class=""></div><div class="">let fn = Foo#doSomething // no longer allowed</div><div class="">let fn = Foo#doSomething() // okay</div><div class="">let fn2 = Foo#doSomething(_:) // okay</div><div class=""><br class=""></div><div class="">// and</div><div class=""><br class=""></div><div class="">let getRow = someMatrix#`subscript`(row:).get</div><div class=""><br class=""></div><div class="">```</div></div><div class=""><br class=""></div><div class=""><br class=""></div></div><div class="gmail_extra" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""><div class="gmail_quote">On Sun, Dec 27, 2015 at 10:40 PM, Douglas Gregor via swift-evolution<span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>></span><span class="Apple-converted-space"> </span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div style="word-wrap: break-word;" class=""><br class=""><div class=""><span class=""><blockquote type="cite" class=""><div class="">On Dec 27, 2015, at 12:27 AM, Frederick Kellison-Linn via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>> wrote:</div><br class=""><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><span class=""></span></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><div class=""><span class=""></span></div><div class=""><div class=""><span class=""></span></div><div class=""><div class="">Given that<span class=""> </span><font face="Menlo" style="font-size: 11px;" class="">someView.insertSubview(_:at:)</font><span class=""> </span>can be correctly parsed, I would strongly lean towards the no-backtick alternative mentioned at the end. I feel as though the backticks end up looking very cluttered (particularly when you get into the double-nested backticks), and it seems cleaner to be able to reference a method as it was declared rather than having to add extra syntax.</div><div class=""><br class=""></div><div class="">In reference to the issues noted with this approach:</div><div class=""><br class=""></div><div class="">IMO, there is already enough syntactic difference between getters/setters and normal methods to justify requiring a different syntax to reference them. For instance, the<span class=""> </span><font face="Menlo" class="">#</font> syntax could be used so that,<span class=""> </span><font face="Menlo" style="font-size: 11px;" class="">button.currentTitle.get</font><span class=""> </span>would reference<span class=""> </span><font face="Menlo" style="font-size: 11px;" class="">Optional<String>.get</font>, and<span class=""> </span><font face="Menlo" style="font-size: 11px;" class="">button.currentTitle#get</font> would reference the getter. Or, <span style="font-family: Menlo; font-size: 11px;" class="">button.`currentTitle.get`</span> could reference the getter (i.e. backticks are only required in cases that are ambiguous).</div><div class=""><br class=""></div><div class="">I also think it is reasonable to require that in the case of a method with no arguments such as <font face="Menlo" style="font-size: 11px;" class="">set.removeAllElements</font><font class="">, the programmer be expected to know the difference between the expression with and without the trailing parenthesis. After all, that distinction already exists in the language, and would not disappear with this proposed addition. If a parallel syntax for referencing methods with no arguments is strongly desired, perhaps something such as </font><span style="font-family: Menlo; font-size: 11px;" class="">set.removeAllElements(:)</span>, <span style="font-family: Menlo; font-size: 11px;" class="">set#removeAllElements()</span>, or similar could be used, though I think that the present system for referencing these methods is sufficient.</div><div class=""><font class=""><br class=""></font></div><div class="">Are there other obvious reasons why this alternative wouldn’t work? I think it is the cleanest of the alternatives and avoids littering the code with backticks.</div></div></div></div></div></blockquote><div class=""><br class=""></div></span><div class="">Not having the back-ticks means that you will need to use contextual type information to disambiguate the zero-parameter case from other cases. For example:</div><div class=""><br class=""></div><div class=""><span style="white-space: pre-wrap;" class="">        </span>class Foo {</div><div class=""><span style="white-space: pre-wrap;" class="">                </span>func doSomething() { }</div><div class=""><span style="white-space: pre-wrap;" class="">                </span>func doSomething(value: Int) { }</div><div class=""><span style="white-space: pre-wrap;" class="">        </span>}</div><div class=""><br class=""></div><div class=""><span style="white-space: pre-wrap;" class="">        </span>let fn = Foo.doSomething // ambiguous</div><div class=""><span style="white-space: pre-wrap;" class="">        </span>let fn2 = Foo.doSomething(_:) // okay</div><div class=""><span style="white-space: pre-wrap;" class="">        </span>let fn3: (Foo) -> () -> Void = Foo.doSomething // okay</div><div class=""><span style="white-space: pre-wrap;" class="">        </span>let fn3: (Foo) -> (Int) -> Void = Foo.doSomething // okay</div><div class=""><br class=""></div><div class="">My general complaint with the “drop the backticks” approach is that it doesn’t solve the whole problem. Sure, it solves 95% of the problem with a little less syntax, but now you need to invent yet another mechanism to handle the other cases (#set, contextual type disambiguation, etc)… which seems inconsistent to me.</div><div class=""><br class=""></div><div class=""><span style="white-space: pre-wrap;" class="">        </span>- Doug</div><div class=""><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div class=""><div class="h5"><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><div class=""><div class=""><div class="">On Dec 26, 2015, at 11:22 PM, Douglas Gregor via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>> wrote:<br class=""><br class=""></div><blockquote type="cite" class=""><div class="">Hi all,<div class=""><br class=""></div><div class="">Here’s a proposal draft to allow one to name any function in Swift. In effect, it’s continuing the discussion of retrieving getters and setters as functions started by Michael Henson here:</div><div class=""><br class=""></div><div class=""><span style="white-space: pre-wrap;" class="">        </span><a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151207/002168.html" target="_blank" class="">https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151207/002168.html</a></div><div class=""><br class=""></div><div class="">the proposal follows, and is available here as well:</div><div class=""><br class=""></div><div class=""><span style="white-space: pre-wrap;" class="">        </span><a href="https://github.com/DougGregor/swift-evolution/blob/generalized-naming/proposals/0000-generalized-naming.md" target="_blank" class="">https://github.com/DougGregor/swift-evolution/blob/generalized-naming/proposals/0000-generalized-naming.md</a></div><div class=""><br class=""></div><div class="">Comments appreciated!</div><div class=""><br class=""></div><div class=""><h1 style="font-size: 2.25em; margin-right: 0px; margin-bottom: 16px; margin-left: 0px; line-height: 1.2; padding-bottom: 0.3em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238); color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; background-color: rgb(255, 255, 255); margin-top: 0px !important;" class="">Generalized Naming for Any Function</h1><ul style="padding: 0px 0px 0px 2em; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class=""><li class="">Proposal: <a href="https://github.com/apple/swift-evolution/blob/master/proposals/0000-generalized-naming.md" target="_blank" style="background-color: transparent; color: rgb(64, 120, 192); text-decoration: none;" class="">SE-NNNN</a></li><li class="">Author(s): <a href="https://github.com/DougGregor" target="_blank" style="background-color: transparent; color: rgb(64, 120, 192); text-decoration: none;" class="">Doug Gregor</a></li><li class="">Status: <strong class="">Awaiting Review</strong></li><li class="">Review manager: TBD</li></ul><h2 style="margin-top: 1em; margin-bottom: 16px; line-height: 1.225; font-size: 1.75em; padding-bottom: 0.3em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238); color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; background-color: rgb(255, 255, 255);" class=""><a href="https://github.com/DougGregor/swift-evolution/blob/generalized-naming/proposals/0000-generalized-naming.md#introduction" target="_blank" style="background-color: transparent; color: rgb(64, 120, 192); text-decoration: none; display: inline-block; padding-right: 2px; line-height: 1;" class=""><span style="font-weight: normal; font-size: 16px; line-height: 1; font-family: octicons; display: inline-block; vertical-align: middle;" class=""></span></a>Introduction</h2><p style="margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class="">Swift includes support for first-class functions, such that any function (or method) can be placed into a value of function type. However, it is not possible to specifically name every function that is part of a Swift program---one cannot provide the argument labels when naming a function, nor are property and subscript getters and setters referenceable. This proposal introduces a general syntax that allows one to name anything that is a function within Swift in an extensible manner.</p><p style="margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class="">Swift-evolution thread: Michael Henson started a thread about the getter/setter issue <a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151207/002168.html" target="_blank" style="background-color: transparent; color: rgb(64, 120, 192); text-decoration: none;" class="">here</a>, continued <a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151214/002203.html" target="_blank" style="background-color: transparent; color: rgb(64, 120, 192); text-decoration: none;" class="">here</a>. See the <a href="https://github.com/DougGregor/swift-evolution/blob/generalized-naming/proposals/0000-generalized-naming.md#alternatives-considered" target="_blank" style="background-color: transparent; color: rgb(64, 120, 192); text-decoration: none;" class="">Alternatives considered</a> section for commentary on that discussion.</p><h2 style="margin-top: 1em; margin-bottom: 16px; line-height: 1.225; font-size: 1.75em; padding-bottom: 0.3em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238); color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; background-color: rgb(255, 255, 255);" class=""><a href="https://github.com/DougGregor/swift-evolution/blob/generalized-naming/proposals/0000-generalized-naming.md#motivation" target="_blank" style="background-color: transparent; color: rgb(64, 120, 192); text-decoration: none; display: inline-block; padding-right: 2px; line-height: 1;" class=""><span style="font-weight: normal; font-size: 16px; line-height: 1; font-family: octicons; display: inline-block; vertical-align: middle;" class=""></span></a>Motivation</h2><p style="margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class="">It's fairly common in Swift for multiple functions or methods to have the same "base name", but be distinguished by parameter labels. For example, <code style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">UIView</code> has three methods with the same base name <code style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">insertSubview</code>:</p><div style="margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class=""><pre style="overflow: auto; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; padding: 16px; background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-wrap: normal; word-break: normal;" class=""><span style="color: rgb(167, 29, 93);" class="">extension</span> UIView {
<span style="color: rgb(167, 29, 93);" class="">func</span> <span style="color: rgb(121, 93, 163);" class="">insertSubview</span>(view: UIView, at <span class="">index</span>: <span style="color: rgb(0, 134, 179);" class="">Int</span>)
<span style="color: rgb(167, 29, 93);" class="">func</span> <span style="color: rgb(121, 93, 163);" class="">insertSubview</span>(view: UIView, aboveSubview <span class="">siblingSubview</span>: UIView)
<span style="color: rgb(167, 29, 93);" class="">func</span> <span style="color: rgb(121, 93, 163);" class="">insertSubview</span>(view: UIView, belowSubview <span class="">siblingSubview</span>: UIView)
}</pre></div><p style="margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class="">When calling these methods, the argument labels distinguish the different methods, e.g.,</p><div style="margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class=""><pre style="overflow: auto; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; padding: 16px; background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-wrap: normal; word-break: normal;" class="">someView<span style="color: rgb(167, 29, 93);" class="">.</span>insertSubview(view, at: <span style="color: rgb(0, 134, 179);" class="">3</span>)
someView<span style="color: rgb(167, 29, 93);" class="">.</span>insertSubview(view, aboveSubview: otherView)
someView<span style="color: rgb(167, 29, 93);" class="">.</span>insertSubview(view, belowSubview: otherView)</pre></div><p style="margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class="">However, when referencing the function to create a function value, one cannot provide the labels:</p><div style="margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class=""><pre style="overflow: auto; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; padding: 16px; background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-wrap: normal; word-break: normal;" class=""><span style="color: rgb(167, 29, 93);" class="">let</span> fn <span style="color: rgb(167, 29, 93);" class="">=</span> someView<span style="color: rgb(167, 29, 93);" class="">.</span>insertSubview <span style="color: rgb(150, 152, 150);" class="">// ambiguous: could be any of the three methods</span></pre></div><p style="margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class="">In some cases, it is possible to use type annotations to disambiguate:</p><div style="margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class=""><pre style="overflow: auto; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; padding: 16px; background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-wrap: normal; word-break: normal;" class=""><span style="color: rgb(167, 29, 93);" class="">let</span> fn: (UIView, <span style="color: rgb(0, 134, 179);" class="">Int</span>) <span style="color: rgb(167, 29, 93);" class="">=</span> someView<span style="color: rgb(167, 29, 93);" class="">.</span>insertSubview <span style="color: rgb(150, 152, 150);" class="">// ok: uses insertSubview(_:at:)</span>
<span style="color: rgb(167, 29, 93);" class="">let</span> fn: (UIView, UIView) <span style="color: rgb(167, 29, 93);" class="">=</span> someView<span style="color: rgb(167, 29, 93);" class="">.</span>insertSubview <span style="color: rgb(150, 152, 150);" class="">// error: still ambiguous!</span></pre></div><p style="margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class="">To resolve the latter case, one must fall back to creating a closure:</p><div style="margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class=""><pre style="overflow: auto; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; padding: 16px; background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-wrap: normal; word-break: normal;" class=""><span style="color: rgb(167, 29, 93);" class="">let</span> fn: (UIView, UIView) <span style="color: rgb(167, 29, 93);" class="">=</span> { view, otherView <span style="color: rgb(167, 29, 93);" class="">in</span>
button<span style="color: rgb(167, 29, 93);" class="">.</span>insertSubview(view, otherView)
}</pre></div><p style="margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class="">which is painfully tedious. A similar workaround is required to produce a function value for a getter of a property, e.g.,</p><div style="margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class=""><pre style="overflow: auto; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; padding: 16px; background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-wrap: normal; word-break: normal;" class=""><span style="color: rgb(167, 29, 93);" class="">extension</span> UIButton {
<span style="color: rgb(167, 29, 93);" class="">var</span> currentTitle: <span style="color: rgb(0, 134, 179);" class="">String</span>? { <span style="color: rgb(167, 29, 93);" class="">...</span> }
}
<span style="color: rgb(167, 29, 93);" class="">var</span> fn: () <span style="color: rgb(167, 29, 93);" class="">-></span> <span style="color: rgb(0, 134, 179);" class="">String</span>? <span style="color: rgb(167, 29, 93);" class="">=</span> { () <span style="color: rgb(167, 29, 93);" class="">in</span>
<span style="color: rgb(167, 29, 93);" class="">return</span> button<span style="color: rgb(167, 29, 93);" class="">.</span>currentTitle
}</pre></div><p style="margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class="">One additional bit of motivation: Swift should probably get some way to ask for the Objective-C selector for a given method (rather than writing a string literal). The argument to such an operation would likely be a reference to a method, which would benefit from being able to name any method, including getters and setters.</p><h2 style="margin-top: 1em; margin-bottom: 16px; line-height: 1.225; font-size: 1.75em; padding-bottom: 0.3em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238); color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; background-color: rgb(255, 255, 255);" class=""><a href="https://github.com/DougGregor/swift-evolution/blob/generalized-naming/proposals/0000-generalized-naming.md#proposed-solution" target="_blank" style="background-color: transparent; color: rgb(64, 120, 192); text-decoration: none; display: inline-block; padding-right: 2px; line-height: 1;" class=""><span style="font-weight: normal; font-size: 16px; line-height: 1; font-family: octicons; display: inline-block; vertical-align: middle;" class=""></span></a>Proposed solution</h2><p style="margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class="">Swift currently has a back-tick escaping syntax that lets one use keywords for names, which would otherwise fail to parse. For example,</p><div style="margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class=""><pre style="overflow: auto; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; padding: 16px; background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-wrap: normal; word-break: normal;" class=""><span style="color: rgb(167, 29, 93);" class="">func</span> <span style="color: rgb(121, 93, 163);" class="">`try`</span>() <span style="color: rgb(167, 29, 93);" class="">-></span> <span style="color: rgb(0, 134, 179);" class="">Bool</span> { <span style="color: rgb(167, 29, 93);" class="">...</span> }</pre></div><p style="margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class="">declares a function named <code style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">try</code>, even though <code style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">try</code> is a keyword. I propose to extend the back-tick syntax to allow compound Swift names (e.g., <code style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">insertSubview(_:aboveSubview:)</code>) and references to the accessors of properties (e.g., the getter for <code style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">currentTitle</code>). Specifically,</p><ul style="padding: 0px 0px 0px 2em; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class=""><li class=""><p style="margin-top: 16px; margin-bottom: 16px;" class="">Compound names can be written entirely within the back-ticks, e.g.,</p><div style="margin-bottom: 16px;" class=""><pre style="overflow: auto; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; padding: 16px; background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-wrap: normal; word-break: normal;" class=""><span style="color: rgb(167, 29, 93);" class="">let</span> fn <span style="color: rgb(167, 29, 93);" class="">=</span> someView<span style="color: rgb(167, 29, 93);" class="">.</span>`insertSubview(_:at:)`
<span style="color: rgb(167, 29, 93);" class="">let</span> fn1 <span style="color: rgb(167, 29, 93);" class="">=</span> someView<span style="color: rgb(167, 29, 93);" class="">.</span>`insertSubview(_:aboveSubview:)`</pre></div><p style="margin-top: 16px; margin-bottom: 16px;" class="">The same syntax can also refer to initializers, e.g.,</p><div style="margin-bottom: 16px;" class=""><pre style="overflow: auto; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; padding: 16px; background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-wrap: normal; word-break: normal;" class=""><span style="color: rgb(167, 29, 93);" class="">let</span> buttonFactory <span style="color: rgb(167, 29, 93);" class="">=</span> UIButton<span style="color: rgb(167, 29, 93);" class="">.</span>`<span style="color: rgb(167, 29, 93);" class="">init</span>(type:)`</pre></div></li><li class=""><p style="margin-top: 16px; margin-bottom: 16px;" class="">Getters and setters can be written using dotted syntax within the back-ticks:</p><div style="margin-bottom: 16px;" class=""><pre style="overflow: auto; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; padding: 16px; background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-wrap: normal; word-break: normal;" class=""><span style="color: rgb(167, 29, 93);" class="">let</span> specificTitle <span style="color: rgb(167, 29, 93);" class="">=</span> button<span style="color: rgb(167, 29, 93);" class="">.</span>`currentTitle<span style="color: rgb(167, 29, 93);" class="">.</span><span style="color: rgb(167, 29, 93);" class="">get</span>` <span style="color: rgb(150, 152, 150);" class="">// has type () -> String?</span>
<span style="color: rgb(167, 29, 93);" class="">let</span> otherTitle <span style="color: rgb(167, 29, 93);" class="">=</span> UIButton<span style="color: rgb(167, 29, 93);" class="">.</span>`currentTitle<span style="color: rgb(167, 29, 93);" class="">.</span><span style="color: rgb(167, 29, 93);" class="">get</span>` <span style="color: rgb(150, 152, 150);" class="">// has type (UIButton) -> () -> String?</span>
<span style="color: rgb(167, 29, 93);" class="">let</span> setTintColor <span style="color: rgb(167, 29, 93);" class="">=</span> button<span style="color: rgb(167, 29, 93);" class="">.</span>`tintColor<span style="color: rgb(167, 29, 93);" class="">.</span><span style="color: rgb(167, 29, 93);" class="">set</span>` <span style="color: rgb(150, 152, 150);" class="">// has type (UIColor!) -> ()</span></pre></div><p style="margin-top: 16px; margin-bottom: 16px;" class="">The same syntax works with subscript getters and setters as well, using the full name of the subscript:</p><div style="margin-bottom: 16px;" class=""><pre style="overflow: auto; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; padding: 16px; background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-wrap: normal; word-break: normal;" class=""><span style="color: rgb(167, 29, 93);" class="">extension</span> Matrix {
<span style="color: rgb(167, 29, 93);" class="">subscript</span> (row row: <span style="color: rgb(0, 134, 179);" class="">Int</span>) <span style="color: rgb(167, 29, 93);" class="">-></span> [<span style="color: rgb(0, 134, 179);" class="">Double</span>] {
<span style="color: rgb(167, 29, 93);" class="">get</span> { <span style="color: rgb(167, 29, 93);" class="">...</span> }
<span style="color: rgb(167, 29, 93);" class="">set</span> { <span style="color: rgb(167, 29, 93);" class="">...</span> }
}
}
<span style="color: rgb(167, 29, 93);" class="">let</span> getRow <span style="color: rgb(167, 29, 93);" class="">=</span> someMatrix<span style="color: rgb(167, 29, 93);" class="">.</span>`<span style="color: rgb(167, 29, 93);" class="">subscript</span>(row:)<span style="color: rgb(167, 29, 93);" class="">.</span><span style="color: rgb(167, 29, 93);" class="">get</span>` <span style="color: rgb(150, 152, 150);" class="">// has type (Int) -> () -> [Double]</span>
<span style="color: rgb(167, 29, 93);" class="">let</span> setRow <span style="color: rgb(167, 29, 93);" class="">=</span> someMatrix<span style="color: rgb(167, 29, 93);" class="">.</span>`<span style="color: rgb(167, 29, 93);" class="">subscript</span>(row:)<span style="color: rgb(167, 29, 93);" class="">.</span><span style="color: rgb(167, 29, 93);" class="">set</span>` <span style="color: rgb(150, 152, 150);" class="">// has type (Int) -> ([Double]) -> ()</span></pre></div><p style="margin-top: 16px; margin-bottom: 16px;" class="">If we introduce property behaviors into Swift, the back-tick syntax could also be used to refer to behaviors, e.g., accessing the <code style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">lazy</code> behavior of a property:</p><div style="margin-bottom: 16px;" class=""><pre style="overflow: auto; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; padding: 16px; background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-wrap: normal; word-break: normal;" class=""><span style="color: rgb(167, 29, 93);" class="">self</span><span style="color: rgb(167, 29, 93);" class="">.</span>`myProperty<span style="color: rgb(167, 29, 93);" class="">.</span><span style="color: rgb(167, 29, 93);" class="">lazy</span>`<span style="color: rgb(167, 29, 93);" class="">.</span>clear()</pre></div></li><li class=""><p style="margin-top: 16px; margin-bottom: 16px;" class="">Base names that are meaningful keywords (<code style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">init</code> and <code style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">subscript</code>) can be escaped with a nested pair of back-ticks:</p><div style="margin-bottom: 16px;" class=""><pre style="overflow: auto; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; padding: 16px; background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-wrap: normal; word-break: normal;" class=""><span style="color: rgb(167, 29, 93);" class="">extension</span> Font {
<span style="color: rgb(167, 29, 93);" class="">func</span> <span style="color: rgb(121, 93, 163);" class="">`subscript`</span>() <span style="color: rgb(167, 29, 93);" class="">-></span> Font {
<span style="color: rgb(150, 152, 150);" class="">// return the subscript version of the given font</span>
}
}
<span style="color: rgb(167, 29, 93);" class="">let</span> getSubscript <span style="color: rgb(167, 29, 93);" class="">=</span> font<span style="color: rgb(167, 29, 93);" class="">.</span>``<span style="color: rgb(167, 29, 93);" class="">subscript</span>`()` <span style="color: rgb(150, 152, 150);" class="">// has type () -> Font</span></pre></div></li></ul><p style="margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class="">The "produce the Objective-C selector for the given method" operation will be the subject of a separate proposal. However, here is one possibility that illustrations how it uses the proposed syntax here:</p><div style="margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class=""><pre style="overflow: auto; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; padding: 16px; background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-wrap: normal; word-break: normal;" class=""><span style="color: rgb(167, 29, 93);" class="">let</span> getter: Selector <span style="color: rgb(167, 29, 93);" class="">=</span> objc_selector(NSDictionary<span style="color: rgb(167, 29, 93);" class="">.</span>`<span style="color: rgb(167, 29, 93);" class="">subscript</span>(_:)<span style="color: rgb(167, 29, 93);" class="">.</span><span style="color: rgb(167, 29, 93);" class="">get</span>`) <span style="color: rgb(150, 152, 150);" class="">// produces objectForKeyedSubscript:</span>
<span style="color: rgb(167, 29, 93);" class="">let</span> setter: Selector <span style="color: rgb(167, 29, 93);" class="">=</span> objc_selector(NSDictionary<span style="color: rgb(167, 29, 93);" class="">.</span>`<span style="color: rgb(167, 29, 93);" class="">subscript</span>(_:)<span style="color: rgb(167, 29, 93);" class="">.</span><span style="color: rgb(167, 29, 93);" class="">set</span>`) <span style="color: rgb(150, 152, 150);" class="">// produces setObject:forKeyedSubscript:</span></pre></div><h2 style="margin-top: 1em; margin-bottom: 16px; line-height: 1.225; font-size: 1.75em; padding-bottom: 0.3em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238); color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; background-color: rgb(255, 255, 255);" class=""><a href="https://github.com/DougGregor/swift-evolution/blob/generalized-naming/proposals/0000-generalized-naming.md#impact-on-existing-code" target="_blank" style="background-color: transparent; color: rgb(64, 120, 192); text-decoration: none; display: inline-block; padding-right: 2px; line-height: 1;" class=""><span style="font-weight: normal; font-size: 16px; line-height: 1; font-family: octicons; display: inline-block; vertical-align: middle;" class=""></span></a>Impact on existing code</h2><p style="margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class="">This is a purely additive feature that has no impact on existing code. The syntactic space it uses is already present, and it merely extends the use of back-ticks from storing a single identifier to more complex names.</p><h2 style="margin-top: 1em; margin-bottom: 16px; line-height: 1.225; font-size: 1.75em; padding-bottom: 0.3em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238); color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; background-color: rgb(255, 255, 255);" class=""><a href="https://github.com/DougGregor/swift-evolution/blob/generalized-naming/proposals/0000-generalized-naming.md#alternatives-considered" target="_blank" style="background-color: transparent; color: rgb(64, 120, 192); text-decoration: none; display: inline-block; padding-right: 2px; line-height: 1;" class=""><span style="font-weight: normal; font-size: 16px; line-height: 1; font-family: octicons; display: inline-block; vertical-align: middle;" class=""></span></a>Alternatives considered</h2><ul style="padding: 0px 0px 0px 2em; margin-top: 0px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255); margin-bottom: 0px !important;" class=""><li class=""><p style="margin-top: 16px; margin-bottom: 16px;" class="">Michael Henson <a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151207/002168.html" target="_blank" style="background-color: transparent; color: rgb(64, 120, 192); text-decoration: none;" class="">proposed</a> naming getters and setters using <code style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">#</code> syntax followed by <code style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">get</code> or <code style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">set</code>, e.g.,</p><div style="margin-bottom: 16px;" class=""><pre style="overflow: auto; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; padding: 16px; background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-wrap: normal; word-break: normal;" class=""><span style="color: rgb(167, 29, 93);" class="">let</span> specificTitle <span style="color: rgb(167, 29, 93);" class="">=</span> button<span style="color: rgb(167, 29, 93);" class="">.</span>currentTitle#<span style="color: rgb(167, 29, 93);" class="">get</span></pre></div><p style="margin-top: 16px; margin-bottom: 16px;" class="">The use of postfix <code style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">#</code> is a reasonable alternative here, and more lightweight than two back-ticks for the simple getter/setter case. The notion could be extended to allow argument labels for functions, discussed <a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151214/002210.html" target="_blank" style="background-color: transparent; color: rgb(64, 120, 192); text-decoration: none;" class="">here</a>. The proposals in that discussion actually included type annotations as well, but the syntax seems cleaner---and more directly focused on <em class="">names</em>---without them, e.g.,:</p><div style="margin-bottom: 16px;" class=""><pre style="overflow: auto; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; padding: 16px; background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-wrap: normal; word-break: normal;" class=""><span style="color: rgb(167, 29, 93);" class="">let</span> fn <span style="color: rgb(167, 29, 93);" class="">=</span> someView<span style="color: rgb(167, 29, 93);" class="">.</span>insertSubview#(_:at:)</pre></div><p style="margin-top: 16px; margin-bottom: 16px;" class="">which works. I didn't go with this syntax because (1) it breaks up Swift method names such as <code style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">insertSubview(_:at:)</code>with an <code style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">#</code> in the middle, and (2) while useful, this feature doesn't seem important enough to justify overloading <code style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">#</code>further.</p></li><li class=""><p style="margin-top: 16px; margin-bottom: 16px;" class="">Joe Groff <a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151214/003008.html" target="_blank" style="background-color: transparent; color: rgb(64, 120, 192); text-decoration: none;" class="">notes</a> that <em class="">lenses</em> are a better solution than manually retrieving getter/setter functions when the intent is to actually operate on the properties. That weakens the case this proposal makes for making getters/setters available as functions. However, it doesn't address the general naming issue or the desire to retrieve the Objective-C selector for a getter/setter.</p></li><li class=""><p style="margin-top: 16px; margin-bottom: 16px;" class="">Can we drop the back-ticks? It's very tempting to want to drop the back-ticks entirely, because something like</p><div style="margin-bottom: 16px;" class=""><pre style="overflow: auto; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; padding: 16px; background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-wrap: normal; word-break: normal;" class=""><span style="color: rgb(167, 29, 93);" class="">let</span> fn <span style="color: rgb(167, 29, 93);" class="">=</span> someView<span style="color: rgb(167, 29, 93);" class="">.</span>insertSubview(_:at:)</pre></div><p style="margin-top: 16px; margin-bottom: 16px;" class="">can be correctly parsed as a reference to <code style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">insertSubview(_:at:)</code>. However, it breaks down at the margins, e.g., with getter/setter references or no-argument functions:</p><div style="margin-bottom: 16px;" class=""><pre style="overflow: auto; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; padding: 16px; background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-wrap: normal; word-break: normal;" class=""><span style="color: rgb(167, 29, 93);" class="">extension</span> <span style="color: rgb(0, 134, 179);" class="">Optional</span> {
<span style="color: rgb(167, 29, 93);" class="">func</span> <span style="color: rgb(121, 93, 163);" class="">get</span>() <span style="color: rgb(167, 29, 93);" class="">-></span> T { <span style="color: rgb(167, 29, 93);" class="">return</span> <span style="color: rgb(167, 29, 93);" class="">self</span><span style="color: rgb(167, 29, 93);" class="">!</span> }
}
<span style="color: rgb(167, 29, 93);" class="">let</span> fn1 <span style="color: rgb(167, 29, 93);" class="">=</span> button<span style="color: rgb(167, 29, 93);" class="">.</span>currentTitle<span style="color: rgb(167, 29, 93);" class="">.</span><span style="color: rgb(167, 29, 93);" class="">get</span> <span style="color: rgb(150, 152, 150);" class="">// getter or Optional<String>.get?</span>
<span style="color: rgb(167, 29, 93);" class="">let</span> fn2 <span style="color: rgb(167, 29, 93);" class="">=</span> <span style="color: rgb(167, 29, 93);" class="">set</span><span style="color: rgb(167, 29, 93);" class="">.</span>removeAllElements() <span style="color: rgb(150, 152, 150);" class="">// call or reference?</span></pre></div></li></ul><div class=""><br class=""></div></div><div class=""><br class=""></div><div class=""><span style="white-space: pre-wrap;" class="">        </span>- Doug</div><div class=""><br class=""></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=xuNk3-2BDhTcLCDO7Sfs7vOE8RaV6tazapi-2F-2FC6t9siri7wqPwj3GTvcsesCn0HCG6qbJOesGeRvdcCHYn8YNs-2B33qAo05m-2FcE15wjx0YFhkMSPKBonVF9XH7KjNWaWg5rjebvzIvHBYbEiZFWK4YgJwDdCAOM16M9EyTB7HFifNwMcCf7jx7srduho1hnunFaproD8Tw9yUpavWrFiHWRug-3D-3D" alt="" width="1" height="1" border="0" style="min-height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;" class=""></div></blockquote><blockquote type="cite" class=""><div class=""><span class="">_______________________________________________</span><br class=""><span class="">swift-evolution mailing list</span><br class=""><span class=""><a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a></span><br class=""><span class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br class=""></div></blockquote></div></div></div></div></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=XbU4wxnU83GyR7TGhOdBtBOchMF7PYvaYPXWDKda2ffTOeR-2BLrUS2cXpCI5wePnWtguWA-2FpwD34TY4-2B37fOYqRlvRBIPqv9pfe-2FPUhuCCJFq3L6XVoD-2FonkVTKBGplgr0eQNgGCilX-2FQfb1oUXhCt0mj4NNuIVFxi2RQbodo9-2FAXoR-2BpM4e9QcQ-2BRa5jvpehMdC0XDpmiw1yLqe6TjwwkXrJm1Y5lsP6XfSrLT7N3Ic-3D" alt="" width="1" height="1" border="0" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; min-height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; float: none; display: inline !important;" class=""><span class=""> </span>_______________________________________________</span><span class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; float: none; display: inline !important;" class="">swift-evolution mailing list</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><a href="mailto:swift-evolution@swift.org" target="_blank" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class="">swift-evolution@swift.org</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span></div></blockquote></div><br class=""><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=3FGfocPbgxkNkmje7djckg9Iw-2BGYY3X6RxJ1tkUXKCoYDOSKYhI4LWPG4aSBKAdirCOIghgFQiIL2oHKWBSOi4d-2FYhpIFZWhMCkBJWp-2FUrEq5OlgFkrQU1zPSN8nLm5nYq2rdp4dgjEy7HsA1iRvkE6j-2BbGlbJTALMYANhqsa6eccwD-2F8pdEQDHz3nWxHj3SUvGfTd-2FCbfrZ510dt3zjtZYUomS0a9j94WWcUVjkEa0-3D" alt="" width="1" height="1" border="0" style="min-height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;" class=""></div><br class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""><br class=""></blockquote></div><br class=""></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=nE9rxSXA5G4kxsTVkgv43vFcOQoCM-2FU-2BigXPSqPoICJuV2MVe5DGoA-2FvDYdWhKNiowJCHFLHaj5JmzGR7mS2opshccpqH2wwOjUrwhAExkhTf9fn3N44Poit7uea4wiEcmi7o9OIxVyZLJa4eHm2nd5Y7ON4hRoKO9VW25sEtnrfD53OtnTQeGcX50KoVLxTxLMl3PwHsbLxW2Yw94m-2Fo2dY8RhbH6BzVBfiMBRMwvU-3D" alt="" width="1" height="1" border="0" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class=""><span class="Apple-converted-space"> </span>_______________________________________________</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">swift-evolution mailing list</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="mailto:swift-evolution@swift.org" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">swift-evolution@swift.org</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br class=""></div></body></html>