<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=""><div><blockquote type="cite" class=""><div class="">On Dec 27, 2015, at 10:37 AM, Joe Groff via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><div class=""><div 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=""><blockquote type="cite" class=""><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><ul class="" style="box-sizing: border-box; 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);"><li class="" style="box-sizing: border-box;"><p class="" style="box-sizing: border-box; margin-top: 16px; margin-bottom: 16px;">Getters and setters can be written using dotted syntax within the back-ticks:</p><div class="highlight highlight-source-swift" style="box-sizing: border-box; margin-bottom: 16px;"><pre class="" style="box-sizing: border-box; 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;"><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">let</span> specificTitle <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> button<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>`currentTitle<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">get</span>` <span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// has type () -> String?</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">let</span> otherTitle <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> UIButton<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>`currentTitle<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">get</span>` <span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// has type (UIButton) -> () -> String?</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">let</span> setTintColor <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> button<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>`tintColor<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">set</span>` <span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// has type (UIColor!) -> ()</span></pre></div><p class="" style="box-sizing: border-box; margin-top: 16px; margin-bottom: 16px;">The same syntax works with subscript getters and setters as well, using the full name of the subscript:</p><div class="highlight highlight-source-swift" style="box-sizing: border-box; margin-bottom: 16px;"><pre class="" style="box-sizing: border-box; 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;"><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">extension</span> Matrix {
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">subscript</span> (row row: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Int</span>) <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">-></span> [<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Double</span>] {
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">get</span> { <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">...</span> }
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">set</span> { <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">...</span> }
}
}
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">let</span> getRow <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> someMatrix<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>`<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">subscript</span>(row:)<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">get</span>` <span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// has type (Int) -> () -> [Double]</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">let</span> setRow <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> someMatrix<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>`<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">subscript</span>(row:)<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">set</span>` <span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// has type (Int) -> ([Double]) -> ()</span></pre></div></li></ul></div></div></div></blockquote><div class="">At least as far as pure Swift is concerned, for unapplied access, like `UIButton.currentTitle`, I think it would be more consistent with the way method references works for that to give you the getter (or lens) without decoration. instance.instanceMethod has type Args -> Ret, and Type.instanceMethod has type Self -> Args -> Ret; by analogy, since instance.instanceProperty has type Ret or inout Ret, it's reasonable to expect Type.instanceProperty to have type Self -> [inout] Ret. Forming a getter or setter partially applied to an instance feels unmotivated to me—{ button.currentTitle } or { button.currentTitle = $0 } already work, and are arguably clearer than this syntax.</div><div class=""><br class=""></div><div class="">I acknowledge that this leaves forming selectors from setters out to dry, but I feel like that's something that could be incorporated into a "lens" design along with typed selectors. As a rough sketch, we could say that the representation of @convention(selector) T -> inout U is a pair of getter/setter selectors, and provide API on Selector to grab the individual selectors from that, maybe Selector(getterFor: UIView.currentTitle)/(setterFor: UIView.currentTitle). I don't think get/set is a good interface for working with Swift properties, so I don't like the idea of building in language support to codify it beyond what's needed for ObjC interaction.</div></div></div></blockquote><div><br class=""></div>I know this might be too early, but: what syntax are we thinking of for lenses? We might want to design this with future consistency in mind.</div><div><br class=""></div><div>John.<br class=""><blockquote type="cite" class=""><div class=""><div 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=""><blockquote type="cite" class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><ul class="" style="box-sizing: border-box; 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;"><li class="" style="box-sizing: border-box;"><p class="" style="box-sizing: border-box; margin-top: 16px; margin-bottom: 16px;">Can we drop the back-ticks? It's very tempting to want to drop the back-ticks entirely, because something like</p><div class="highlight highlight-source-swift" style="box-sizing: border-box; margin-bottom: 16px;"><pre class="" style="box-sizing: border-box; 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;"><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">let</span> fn <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> someView<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>insertSubview(_:at:)</pre></div><p class="" style="box-sizing: border-box; margin-top: 16px; margin-bottom: 16px;">can be correctly parsed as a reference to <code class="" style="box-sizing: border-box; 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;">insertSubview(_:at:)</code>. However, it breaks down at the margins, e.g., with getter/setter references or no-argument functions:</p><div class="highlight highlight-source-swift" style="box-sizing: border-box; margin-bottom: 16px;"><pre class="" style="box-sizing: border-box; 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;"><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">extension</span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Optional</span> {
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">get</span>() <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">-></span> T { <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">return</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">self</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">!</span> }
}
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">let</span> fn1 <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> button<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>currentTitle<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">get</span> <span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// getter or Optional<String>.get?</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">let</span> fn2 <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">set</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>removeAllElements() <span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// call or reference?</span></pre></div></li></ul></div></div></blockquote>From what I remember, the bigger concern with allowing foo(bar:bas:) without backticks is parser error recovery. The unambiguity with call syntax depends on having the `:)` token pair at the end. The edit distance between foo(bar:bas:) and a call foo(bar: bas) or work-in-progress call foo(bar: x, bas: ) is pretty slight, and would be tricky to give good diagnostics for. If we felt confident we could give good diagnostics, I'd support removing the backticks.</div><div 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=""><br class=""></div><div 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="">-Joe</div><br class="" 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;"><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=hWKWvOREWCPT32eVzNXOV7yIWXgGOvlMtgjKbOieJnabs6EvnZ7z3KRfGOfFrmMtCtI2NctphRrz4nRrKoR6nTvid2kaULNrs2rr6rcNLSgxPIfX4zhtFBmZdR-2FMdfFe3OfUUMrXYc1pUdxhg35mXXAIqrQrMF5ih2bNqt75vQxeR4NwSgv3Tjh6S2M2Fetvv-2BTpBDS-2BEQtO-2FeHfJSBUYTX40OoMicN56HoE8fFKIUk-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><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><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=""></body></html>