<html><head></head><body><div>That would be handy<br><br><div class="acompli_signature">Sent from <a dir="ltr" href="http://supmenow.com" x-apple-data-detectors="true" x-apple-data-detectors-type="link" x-apple-data-detectors-result="0">Supmenow.com</a></div><br></div><br><br><br>
<div class="gmail_quote">On Sat, Apr 30, 2016 at 1:31 PM -0700, "David Sweeris via swift-evolution" <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="3D"ltr"">
<meta http-equiv="Content-Type" content="text/html charset=utf-8"><div class=""><div class=""><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Apr 30, 2016, at 7:18 AM, Rod Brown via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><div class=""><div dir="auto" class=""><div class=""><br class=""></div><div class="">I think this specific proposal asking for compiler magic to auto-unwrap invisibly and only in very limited cases, as this proposal suggests, ends up breaking a lot more than it fixes. I can only see circumstances of this working with variables in the current scope, as anything like a property could be updated by other methods, threads etc, and the compiler couldn't be certain of state.</div><div class=""><br class=""></div><div class="">I think a language feature like you describe would be a lot more helpful, but I'd love to hear others' views on that.</div><div class=""><br class="">- Rod</div></div></div></blockquote></div><div class=""><br class=""></div>Yeah, auto-unwrapping "wherever it might be possible" seems too magical to me. I wouldn’t object to the compiler auto-unwraping optionals within a well defined code block, though:<div class=""><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">//foo is T?</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">if</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);" class="">foo</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> != </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">nil</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> {</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">//foo is T within this set of curly braces</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">}</span></div><div class="">But even that invokes a bit of compiler magic, in that for this one type of enum (`Optional`), the compiler knows that if it isn’t one case, it must be the other. I’d prefer a more general solution…</div><div class=""><br class=""></div><div class="">What if the “is” keyword could function as a kind of incomplete switch?</div></div><blockquote style="margin: 0px 0px 0px 40px; border: none; padding: 0px;" class=""><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="font-family: Menlo; color: rgb(112, 61, 170); margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">var</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class=""> foo: </span><span style="font-variant-ligatures: no-common-ligatures;" class="">UnicodeDecodingResult</span></div></div></div></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="font-family: Menlo; margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">...</span></div></div></div></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="font-family: Menlo; color: rgb(0, 132, 0); margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">if</span><span style="color: rgb(112, 61, 170); font-variant-ligatures: no-common-ligatures;" class=""> foo </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">is</span><span style="color: rgb(112, 61, 170); font-variant-ligatures: no-common-ligatures;" class=""> .Result {</span></div></div></div></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="font-family: Menlo; color: rgb(0, 132, 0); margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class=""> </span><span style="font-variant-ligatures: no-common-ligatures;" class="">//since we know foo is a result, `foo` refers to foo's associated or raw value within this set of curly braces</span></div></div></div></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="font-family: Menlo; color: rgb(112, 61, 170); margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">}</span></div></div></div></span></div></blockquote><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">This allows the language feature (and relevant compiler code paths) to be used with <i class="">any</i> enum, not just Optionals. The “optional unwrapping behavior" could then be written like this:</span></div><blockquote style="margin: 0px 0px 0px 40px; border: none; padding: 0px;" class=""><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="font-family: Menlo; margin: 0px; line-height: normal;" class=""><span style="color: rgb(187, 44, 162); font-variant-ligatures: no-common-ligatures;" class="">var</span><span style="font-variant-ligatures: no-common-ligatures;" class=""><font color="#703daa" class=""> bar</font> = </span><span style="color: rgb(39, 42, 216); font-variant-ligatures: no-common-ligatures;" class="">4</span><span style="color: rgb(112, 61, 170); font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="color: rgb(187, 44, 162); font-variant-ligatures: no-common-ligatures;" class="">as</span><span style="color: rgb(112, 61, 170); font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="color: rgb(112, 61, 170); font-variant-ligatures: no-common-ligatures;" class="">Int</span><span style="color: rgb(112, 61, 170); font-variant-ligatures: no-common-ligatures;" class="">?</span></div></div></div></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="font-family: Menlo; margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">...</span></div></div></div></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="font-family: Menlo; color: rgb(112, 61, 170); margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">if</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> bar </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">is</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> .Some {</span></div></div></div></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="font-family: Menlo; color: rgb(0, 132, 0); margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class=""> </span><span style="font-variant-ligatures: no-common-ligatures;" class="">//bar is 4 within this set of curly braces</span></div></div></div></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="font-family: Menlo; color: rgb(112, 61, 170); margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">}</span></div></div></div></span></div></blockquote><div class=""><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="font-family: Menlo; color: rgb(112, 61, 170);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><br class=""></span></div></div></div></span></div><div class="">- Dave Sweeris</div></div></div></div></div></div><div class=""><br class=""></div>
</div>
</blockquote>
</div>
</body></html>