<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 30, 2015, at 4:23 PM, 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=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Dec 30, 2015, at 5:19 PM, Kevin Ballard 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="">


<title class=""></title>

<div class=""><div class="">On Wed, Dec 30, 2015, at 03:12 PM, Kevin Wooten via swift-evolution wrote:<br class=""></div>
<blockquote type="cite" class=""><div class=""><blockquote type="cite" class=""><div class=""><blockquote 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;" type="cite" class=""><div class=""><div class="">&nbsp;</div>
<div class="">Another possibility I've thought of is defining `defer { val }` to guarantee that val remains alive until the defer fires on scope exit. That might let us leave `defer` as the one "guarantee something happens exactly at scope exit" language construct.<br class=""></div>
</div>
</blockquote></div>
</blockquote><div class="">&nbsp;</div>
<div class="">What about this…<br class=""></div>
<div class="">&nbsp;</div>
<div class=""><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:13px;line-height:normal;font-family:Menlo;" class=""><span class="colour" style="color:rgb(187, 44, 162)">defer</span> <span class="colour" style="color:rgb(187, 44, 162)">let</span>&nbsp;val = grabOrCreateSomething() {<br class=""></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:13px;line-height:normal;font-family:Menlo;" class="">&nbsp; return;<br class=""></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:13px;line-height:normal;font-family:Menlo;min-height:15px;" class="">}<br class=""></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:13px;line-height:normal;font-family:Menlo;" class="">&nbsp;</div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;line-height:normal;" class="">Seems natural once you learn guard.<br class=""></div>
</div>
</div>
</blockquote><div class="">&nbsp;</div>
<div class="">Natural? I have no idea what you're expecting that expression to actually do. What is a "defer let”?<br class=""></div></div></div></blockquote><div class=""><br class=""></div><div class="">I think the idea is that a local variable declared with a `defer` modifier has its lifetime extended until the scope exits. &nbsp;It is a slightly more compact version of what Joe suggested. &nbsp;But I agree that it has potential for confusion - it reads like it is deferring the initialization of `val` until the scope exits which would be rather pointless.</div><div class=""><br class=""></div></div></div></div></blockquote><div><br class=""></div><div>Given our discussion that’s definitely the gist of it, but I do stand corrected. &nbsp;I guess I meant the syntax felt “familiar” to guard, but I'd agree upon reflection it doesn’t read well.</div><div><br class=""></div><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div class="">I do like the idea of making the extended lifetime part of the local variable declaration but I’m not sure about how this specific syntax reads.</div><br class=""><blockquote type="cite" class=""><div class=""><div class="">
<div class="">&nbsp;</div>
<div class="">-Kevin</div>
<div class="">&nbsp;</div>

<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=eLFMrKDT8iBxZ-2Fbnk-2BZqvSchNN-2FvYXdceA0T7VxwkAe9Me-2B3-2FsQVJR-2BVjfoT3XCbvgezTuF8sCYUJ2YXD2IdDwzK-2BCOF7klhH7T-2BOWT1W-2BzHgiFPB3rNjn-2FsBaQwafZpXj-2BvwmVQzeHN9WCXijH9RUzU7OKY8FJssHgDdz0bl1f54-2FZybVN4K3NcevU7KqYpPX3c5Yyv4G3m7hSMc5VJmVwCNZJRmnidrcjMTha5fyY-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="">
</div>


_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class="">
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=1Ry8ov4zuU66O51YNcjYWc9Gs8dpEEeIr-2F04dQY0gBSbNNvxZSk7UrjqjbF1Lsp9A1NXHKMYwkc7Ny2cRYEpFcQmD3-2BlGW9V1iy8-2BpzoK7DV-2BnmesiwnXzAaHc9-2FhMLyDKOiTypxOPQzyw1fWpDfRyGemT5g4HcpBVF9kRk1MdVtW4WG5FyDTgJ8UNrVFjMDHjfcGBntjhaNkxuk1hIQMw-3D-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="">
</div>
_______________________________________________<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=""></body></html>