<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Oct 26, 2017, at 10:27 PM, Howard Lovatt <<a href="mailto:howard.lovatt@gmail.com" class="">howard.lovatt@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">> <span style="font-size:12.8px" class="">Closures cannot replace all uses of local functions. Local functions can be recursive, and have a generic parameter list.</span><div class="gmail-yj6qo gmail-ajU" style="font-size:12.8px"></div><br class=""><div class="">My response would be add these featurtes to closures, it will make closures better.</div></div></div></blockquote><div><br class=""></div>Since closures are first class values, giving closures the ability to define their own generic parameters means the type system would now need to support higher-rank polymorphism. This is a complex feature...</div><div><br class=""></div><div><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><br class=""></div><div class="">In terms of recursion you can fiddle it:</div><div class=""><br class=""></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px" class="">struct RecursiveClosure<C> {<br class=""> var c: C! = nil<br class="">}<br class="">func factorial(_ n: Int) -> Int {<br class=""> var recursive = RecursiveClosure<(Int) -> Int>()<br class=""> recursive.c = { x in<br class=""> (x == 0) ? 1 : x * recursive.c(x - 1)<br class=""> }<br class=""> return recursive.c(n)<br class="">}<br class="">factorial(5) // 120</blockquote></div></div></blockquote><div><br class=""></div><div>Sure, this is just the Scheme letrec-to-let transform done by hand. But at this point, it’s clearly worse than defining a local function, even more so if you have multiple mutually recursive local functions.</div><div><br class=""></div><div>Slava</div><br class=""><blockquote type="cite" class=""><div class=""><div class="gmail_extra"><br clear="all" class=""><div class=""><div class="gmail_signature" data-smartmail="gmail_signature"> -- Howard.<br class=""></div></div>
<br class=""><div class="gmail_quote">On 27 October 2017 at 15:53, Slava Pestov <span dir="ltr" class=""><<a href="mailto:spestov@apple.com" target="_blank" class="">spestov@apple.com</a>></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;line-break:after-white-space" class=""><br class=""><div class=""><span class=""><br class=""><blockquote type="cite" class=""><div class="">On Oct 26, 2017, at 9:52 PM, Howard Lovatt <<a href="mailto:howard.lovatt@gmail.com" target="_blank" class="">howard.lovatt@gmail.com</a>> wrote:</div><br class="m_9145374068027432411Apple-interchange-newline"><div class=""><div dir="ltr" class="">It would be easy to provide a fixit.</div></div></blockquote><div class=""><br class=""></div></span>That is still a source breaking change that requires migration, though.</div><div class=""><span class=""><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""> How often are they actually used? I rarely use them and all my use cases could be a closure instead. <div class=""><br class=""></div><div class="">Also see Mike Kluev example; local functions are arguably worse than closures in all cases (provided that you can appropriately annotate the function type).</div></div></div></blockquote><div class=""><br class=""></div></span>Closures cannot replace all uses of local functions. Local functions can be recursive, and have a generic parameter list.</div><span class="HOEnZb"><font color="#888888" class=""><div class=""><br class=""></div><div class="">Slava</div></font></span><span class=""><div class=""><br class=""><blockquote type="cite" class=""><div class=""><div class="gmail_extra"><br clear="all" class=""><div class=""><div class="m_9145374068027432411gmail_signature" data-smartmail="gmail_signature"> -- Howard.<br class=""></div></div>
<br class=""><div class="gmail_quote">On 27 October 2017 at 12:26, Slava Pestov <span dir="ltr" class=""><<a href="mailto:spestov@apple.com" target="_blank" class="">spestov@apple.com</a>></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;line-break:after-white-space" class=""><span class=""><br class=""><div class=""><br class=""><blockquote type="cite" class=""><div class="">On Oct 26, 2017, at 4:45 PM, Howard Lovatt via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>> wrote:</div><br class="m_9145374068027432411m_8201084941564550245Apple-interchange-newline"><div class=""><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps: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="">Rather than expand local function syntax why not deprecate local functions completely</span></div></blockquote></div><br class=""></span><div class="">I don’t think at this point such a drastic change to the language is likely to happen.</div><span class="m_9145374068027432411HOEnZb"><font color="#888888" class=""><div class=""><br class=""></div><div class="">Slava</div></font></span></div></blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></span></div></blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></body></html>