<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Could you please explain what a lens is/means? I only found [1], but quick skimming didn't reveal any lenses.<div class=""><br class=""></div><div class="">[1]&nbsp;<a href="https://www.youtube.com/watch?v=estNbh2TF3E" class="">https://www.youtube.com/watch?v=estNbh2TF3E</a><br class=""><div class=""><br class=""></div><div class="">A.</div><div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 15, 2016, at 6:10 AM, Michael Henson via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">There hasn't been a major Lens thread on the list so far, but I'm intrigued by the idea and was tinkering with a related proposal until I stumbled across Brandon William's "Lenses in Swift" video and discovered that Lenses cover everything I wanted to do and more.<br class=""><br class="">The one thing that stuck with me, though, is the question of syntax. If Lenses are to be a native part of the Swift language, how would one declare them?<br class=""><br class="">We've currently got not-so-secret methods at the type level of Structs and Classes for every member function:<br class=""><br class="">class Example {<div class="">&nbsp; &nbsp; func action() {}</div><div class="">}</div><div class=""><br class=""></div><div class="">let example = Example()</div><div class="">example.action // () -&gt; Void</div><div class="">Example.action // (Example) -&gt; Void<br class=""><br class="">That looks a lot like a Lens on the member function, though if I understand correctly the current plan is for those to go away in a future version.<br class=""><br class="">We also have to deal with Type-level members and functions:<br class=""><br class="">class Example {</div><div class="">&nbsp; &nbsp;static action() {}</div><div class="">&nbsp; &nbsp;static name: String</div><div class="">}</div><div class=""><br class=""></div><div class="">Example.action() // () -&gt; Void<br class="">Example.name // String<br class=""><br class="">So, using a dot-operator as the way to get a Lens could be problematic due to name collisions.<br class=""><br class="">The Proposal:<br class=""><br class="">Use the '#' character in place of the dot operator to retrieve a Lens for a Type/member pair:<br class=""><br class="">Example#action() // (Example) -&gt; Void<br class="">Example#name &nbsp; &nbsp;// Lens&lt;Example,String&gt;, autogenerated to work on the 'name' member</div><div class=""><br class="">Member function names should be fully-specified with the mechanism from Doug Gregor's method naming proposal.<br class=""><br class="">Some notes:<br class="">* A specific operator stands out and is easier to scan for as a code reader.</div><div class="">* The octothorpe seems to be available in Swift.<br class=""></div><div class="">* It also has a current meaning in a technology familiar to most everyone - the Document Fragment in HTML - which could make the idea easier to explain to newcomers, by analogy.<br class=""><br class="">What about Lenses on Type-level members? My first thought is that we don't have to support that because they're more like namespaced globals rather than parts of a data type. They can always be referenced directly. That might be a vacuous observation to people more familiar with the Lens concept, but I noted it for completeness.<br class=""><br class="">Mike</div></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=LRtxqIpN0uduUbaiFaLozLZv7i-2BSLNOBgkrlBNK2PSWsFR-2F8KF21afhZNNq3EK6M8imH-2B-2FGE8E7MBylPP43W5v-2FvrjRDh-2F4oEV6NGtgBM9nIbQYZ5jLkI9uhy3q4tLRtEa-2BHi-2B-2Fksq-2FVSjS9ior3ppVLzjHpxrwSs9b4o6Xd-2Fm3cfqAiW6cjRzt3xh8EXx-2FqVe7H8UIxwb7tKZFsWX5mOyPF1cGrNH9ZQxpMkGQ-2FHpI-3D" alt="" width="1" height="1" border="0" style="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="">
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></div></body></html>