<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="">Hi Matthew,<div class=""><br class=""><div class="">Finally found time to read the proposal. Much better than the previous iterration. I’m not a huge fan of the proposed syntax either but don’t have the energy for bike shedding :)</div><div class=""><br class=""></div><div class="">As a side note, I’d like to say that I would not use this very often. I much more often use <b class="">unowned</b> capture variables when its clear that the closure can’t outlive the captured variable. For example, my code often looks like this:</div><div class=""><br class=""></div><div class=""><font face="Menlo" class="">class&nbsp;MyViewController :&nbsp;UIViewController&nbsp;{<br class="">&nbsp; &nbsp;&nbsp;var&nbsp;button:&nbsp;ActionButton!<br class="">&nbsp; &nbsp;&nbsp;<br class="">&nbsp; &nbsp;&nbsp;override&nbsp;func&nbsp;viewDidLoad() {<br class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;super.viewDidLoad()<br class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;button.addAction&nbsp;{ [unowned&nbsp;self]&nbsp;in<br class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;print("self:&nbsp;\(self)")<br class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;}<br class="">&nbsp; &nbsp;&nbsp;}<br class="">}</font></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 20 Feb 2017, at 18:01, Matthew Johnson 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 class=""><br class=""><blockquote type="cite" class="">On Feb 20, 2017, at 8:33 AM, Florent Bruneau &lt;<a href="mailto:florent.bruneau@intersec.com" class="">florent.bruneau@intersec.com</a>&gt; wrote:<br class=""><br class=""><br class=""><br class=""><blockquote type="cite" class="">Le 20 févr. 2017 à 06:35, Brent Royal-Gordon via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; a écrit :<br class=""><br class=""><blockquote type="cite" class="">On Feb 19, 2017, at 2:57 PM, Matthew Johnson via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class="">A guarded closure may be created by prefixing a bound instance method reference with the `?` sigil:<br class=""><br class="">```swift<br class="">let guarded = ?myObject.myMethod<br class=""><br class="">// desugars to:<br class="">let guarded = { [weak myObject] in<br class="">guard let myObejct = myObject else {<br class=""> return<br class="">}<br class="">myObject.myMethod()<br class="">}<br class="">```<br class=""></blockquote><br class="">I like this in principle, but I don't like the syntax. The `?` is cryptic and looks pretty strange in prefix position. I think what I'd like to see is:<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>let guarded = weak myObject.myMethod<br class=""></blockquote><br class="">I like the idea of weak closures even if this may conflict with the fact closures are already internally refcounted object. While we cannot have weak references to closure in the language, using `weak` might be misleading in some ways.<br class=""><br class="">In term of syntax, the `weak` keyword looks nice (much better than the '?' and @guarded once). The weak could be used on both sides.<br class=""><br class="">```swift<br class="">addAction(action: weak Action)<br class="">addAction(action: weak myAction)<br class="">```<br class=""><br class="">However, I think this might still look weird with inlined closures, in particular in case you use the suffix syntax for closures:<br class=""><br class="">```swift<br class="">addAction() weak {<br class=""> &nbsp;&nbsp;/* */<br class="">}<br class="">```<br class=""></blockquote><br class=""><br class="">We wouldn’t want to use `weak` if this has the guarded behavior I proposed. &nbsp;We could use `guarded` though.<br class=""><br class="">There are a couple of important things enabled by having the language implement the guarded behavior. &nbsp;<br class=""><br class="">First, the implementation could release the entire closure context as soon as one of the guarded captures is released. &nbsp;This is not possible if users write the code out manually. &nbsp;Second, in the future directions I discuss allowing libraries to detect that the guard has been triggered and the closure has become a no-op. &nbsp;This is also not possible when users write the guard out manually and would be quite desirable for libraries that want to discard their reference to the closure after it becomes a no-op.<br class=""><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="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></div></blockquote></div><br class=""></div></div></body></html>