<div dir="ltr">The inference algebra just suggested was enjoyable to read, but is still a new syntax. Which is interesting and deserving of its own proposal. The purpose of this proposal is simply to introduce the existing capture syntax to local functions. Thanks to everyone's feedback pointing out that the `self` reference analysis is a deeper question than initially realized. <div><br></div><div>Alex</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Nov 14, 2017 at 4:36 PM, Mike Kluev via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><span class="">On 14 November 2017 at 21:02, David Hart <span dir="ltr"><<a href="mailto:david@hartbit.com" target="_blank">david@hartbit.com</a>></span> wrote:<br></span><div class="gmail_extra"><div class="gmail_quote"><span class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space"><br><div><span class="m_-5026886634801406416gmail-"><div><br></div></span>I’d be very hesitant to introduce this syntax:</div><div><br></div><div><ul class="m_-5026886634801406416gmail-m_2863118398544756606MailOutline"><li>it’s new syntax, so it comes with a complexity tax (it isn’t naturally obvious what it means for a func to be weak)</li><li>it’s only sugar for the capture of self</li></ul></div></div></blockquote></span><div>it might cover well over 90% of use cases (by my "pessimistic" estimate)... if someone has a quick way to scan and analyse, say, github swift sources we may even know that current percentage number of real life usage.</div><span class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space"><div><ul class="m_-5026886634801406416gmail-m_2863118398544756606MailOutline"><li>it doesn’t transpose well to local closures</li></ul></div></div></blockquote><div><br></div></span><div>the last one - maybe not. follow me:</div><div><br></div><div>let closure = { [weak self, bar] in ... }</div><div><br></div><div>which today can be written as: <br></div><div><br></div><div>let closure = { [weak self, bar] () -> Int in ... } // full form</div><div><br></div><div>or as:</div><div><br></div><div><div>let closure: () -> Int = { [weak self, bar] in ... } // full form</div></div><div><br></div><div><div>which allows this change:<br></div></div><div><br></div><div>let closure: [weak self, bar] () -> Int = { ... } // full alt form</div><div><br></div><div>or in alternative form:</div><div><br></div><div><div>let closure: weak () -> Int = { [bar] in ... } // short hand form</div></div><div><br></div><div>same can be with functions:</div><div><br></div><div>func fn() -> Int { [weak self, bar] in ... } // full form</div><div><br></div><div>weak func fn() -> Int { [bar] in ... } // short hand form</div><div><br></div><div>the two capture attributes will in practice be "close" to each other:</div><div><br></div><div><div>weak func fn() {</div><div> [bar] in</div><div> ....</div><div>}</div></div><div><br></div><div>and in majority of cases there will be only weak self:</div><div><br></div><div><div>weak func fn() {</div><div> ....<br></div><div>}</div></div><div><br></div><div>Mike</div><div><br></div></div></div></div>
<br>______________________________<wbr>_________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br>
<br></blockquote></div><br></div>