<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 11, 2016, at 11:12 AM, T.J. Usiyan &lt;<a href="mailto:griotspeak@gmail.com" class="">griotspeak@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="">I thought that the backpacks were workable but this does look nicer.&nbsp;</div></div></div></blockquote><div><br class=""></div><div>Backticks were workable and general but ugly.</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><br class=""></div><div class="">Is there any way to specify which module/framework you are pulling the selector from? Is that information even part of the selector? Am I overestimated the usefulness of that possibility?<br class=""></div></div></div></blockquote><div><br class=""></div><div>This is about naming functions. You can use “modulename.fnname(arglabel1:arglabel2:)” to name a specific function from a module.</div><div><br class=""></div><span class="Apple-tab-span" style="white-space:pre">        </span>- Doug</div><div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><br class=""></div><div class="">TJ</div><div class=""><br class=""></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Mon, Jan 11, 2016 at 2:03 PM, Douglas Gregor via swift-evolution <span dir="ltr" class="">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="">Hi all,<div class=""><br class=""></div><div class="">I’ve updated and simplified my “Generalized Naming for Any Function” proposal to only deal with naming functions with argument labels, and dropping the back-ticks. Comments welcome! Proposal is here</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="">and inline:</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="">Naming Functions with Argument Labels</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:&nbsp;<a href="https://github.com/apple/swift-evolution/blob/master/proposals/0000-generalized-naming.md" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none" target="_blank" class="">SE-NNNN</a></li><li class="">Author(s):&nbsp;<a href="https://github.com/DougGregor" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none" target="_blank" class="">Doug Gregor</a></li><li class="">Status:&nbsp;<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/tree/generalized-naming#introduction" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none;display:inline-block;padding-right:2px;line-height:1" target="_blank" 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, when specifying the name of a function, one can only provide the base name, (e.g.,&nbsp;<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>) without the argument labels. For overloaded functions, this means that one must disambiguate based on type information, which is awkward and verbose. This proposal allwos one&nbsp;</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="">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: The first draft of this proposal was discussed&nbsp;<a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151221/004555.html" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none" target="_blank" class="">here</a>. It included support for naming getters/setters (separately brought up by Michael Henson&nbsp;<a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151207/002168.html" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none" target="_blank" class="">here</a>, continued&nbsp;<a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151214/002203.html" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none" target="_blank" class="">here</a>). Joe Groff&nbsp;<a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151221/004579.html" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none" target="_blank" class="">convinced</a>&nbsp;me that lenses are a better approach for working with getters/setters, so I've dropped them from this version of the proposal.</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/tree/generalized-naming#motivation" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none;display:inline-block;padding-right:2px;line-height:1" target="_blank" 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,&nbsp;<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>&nbsp;has three methods with the same base name&nbsp;<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, aboveSubview: 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.&nbsp;</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="">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/tree/generalized-naming#proposed-solution" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none;display:inline-block;padding-right:2px;line-height:1" target="_blank" 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="">I propose to extend function naming to allow compound Swift names (e.g.,&nbsp;<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>) anywhere a name can occur. Specifically,</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(_: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: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 same syntax can also refer to initializers, 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="">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><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 <span style="color:rgb(167,29,93)" class="">=</span> Selector(NSDictionary<span style="color:rgb(167,29,93)" class="">.</span>insertSubview(_:aboveSubview:)) <span style="color:rgb(150,152,150)" class="">// produces insertSubview:aboveSubview:.</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/tree/generalized-naming#detailed-design" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none;display:inline-block;padding-right:2px;line-height:1" target="_blank" class=""><span style="font-weight: normal; font-size: 16px; line-height: 1; font-family: octicons; display: inline-block; vertical-align: middle;" class=""></span></a>Detailed Design</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="">Grammatically, the&nbsp;<em class="">primary-expression</em>&nbsp;grammar will change from:</p><pre style="overflow:auto;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;margin-top:0px;margin-bottom:16px;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;color:rgb(51,51,51)" class=""><code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;padding:0px;margin:0px;background-color:transparent;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-break:normal;border:0px;display:inline;line-height:inherit;word-wrap:normal" class="">primary-expression -&gt; identifier generic-argument-clause[opt]
</code></pre><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:</p><pre style="overflow:auto;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;margin-top:0px;margin-bottom:16px;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;color:rgb(51,51,51)" class=""><code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;padding:0px;margin:0px;background-color:transparent;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-break:normal;border:0px;display:inline;line-height:inherit;word-wrap:normal" class="">primary-expression -&gt; unqualified-name generic-argument-clause[opt]

unqualified-name -&gt; identifier
                  | identifier '(' ((identifier | '_') ':')+ ')'
</code></pre><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="">Within the parentheses, the use of "+" is important, because it disambiguates:</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="">f()</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="">as a call to&nbsp;<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="">f</code>&nbsp;rather than a reference to an&nbsp;<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="">f</code>&nbsp;with no arguments. Zero-argument function references will still require disambiguation via contextual type information.</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/tree/generalized-naming#impact-on-existing-code" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none;display:inline-block;padding-right:2px;line-height:1" target="_blank" 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.</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/tree/generalized-naming#alternatives-considered" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none;display:inline-block;padding-right:2px;line-height:1" target="_blank" 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="">Joe Groff&nbsp;<a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151214/003008.html" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none" target="_blank" class="">notes</a>&nbsp;that&nbsp;<em class="">lenses</em>&nbsp;are a better solution than manually retrieving getter/setter functions when the intent is to actually operate on the properties.</p></li><li class=""><p style="margin-top:16px;margin-bottom:16px" class="">Bartlomiej Cichosz&nbsp;<a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151228/004739.html" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none" target="_blank" class="">suggests</a>&nbsp;a general partial application syntax using&nbsp;<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>&nbsp;as a placeholder, 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="">aGameView<span style="color:rgb(167,29,93)" class="">.</span>insertSubview(_, aboveSubview: playingSurfaceView)</pre></div><p style="margin-top:16px;margin-bottom:16px" class="">When all arguments are&nbsp;<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>, this provides the ability to name any method:</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="">aGameView<span style="color:rgb(167,29,93)" class="">.</span>insertSubview(_, aboveSubview: _)</pre></div><p style="margin-top:16px;margin-bottom:16px" class="">I decided not to go with this because I don't believe we need such a general partial application syntax in Swift. Closures using the $ names are nearly as concise, and eliminate any questions about how the&nbsp;<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>&nbsp;placeholder maps to an argument of the partially-applied function:</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="">{ aGameView<span style="color:rgb(167,29,93)" class="">.</span>insertSubview($<span style="color:rgb(0,134,179)" class="">0</span>, aboveSubview: playingSurfaceView) }</pre></div></li></ul><div class=""><br class=""></div></div><div class=""><br class=""></div><div class=""><br class=""></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=3FGfocPbgxkNkmje7djckg9Iw-2BGYY3X6RxJ1tkUXKCr-2Fld-2FCeVitf1sPvwon4rOYAQLGsABXOcG-2FwlQrKUiUYF-2Frzq1xAvrI7RaGq8fsmswn8j-2BbX-2FvuncNdEOq0wtISI67NN10s474KNC0sqDnGAPuoj1DriE1ubO1avVeJOqdMwvxxS9FN8sbJY9Cvsje0FCa9-2FpHbXL7JXvpggmC-2BNhVZhxjlcWU0CwTGASYXolc-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!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>
</div></blockquote></div><br class=""></body></html>