<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body><div style="font-family:Arial;">I second Xiaodi on this. The syntax feels like a slam-dunk. The only concerns I have are indentation, and ultimately that's not my problem to decide about. ;)<br></div>
<div style="font-family:Arial;"><br></div>
<div id="sig20055365"><div class="signature"><span class="font" style="font-family:arial, sans-serif, sans-serif">Sincerely,</span><span class="font" style="font-family:arial, sans-serif, sans-serif"></span><br></div>
<div class="signature"><span class="font" style="font-family:arial, sans-serif, sans-serif">&nbsp; Zachary Waldowski</span><span class="font" style="font-family:arial, sans-serif, sans-serif"></span><br></div>
<div class="signature"><span class="font" style="font-family:arial, sans-serif, sans-serif">&nbsp;&nbsp;</span><a href="mailto:zach@waldowski.me"><span class="font" style="font-family:arial, sans-serif, sans-serif">zach@waldowski.me</span></a><span class="font" style="font-family:arial, sans-serif, sans-serif"></span><br></div>
<div style="font-family:Arial;"><br></div>
<div style="font-family:Arial;">On Wed, Jul 5, 2017, at 07:15 PM, Xiaodi Wu via swift-evolution wrote:<br></div>
</div>
<blockquote type="cite"><div dir="ltr"><div style="font-family:Arial;">Initially, this proposal felt a little off, but on re-reading, I think I like it very much. It shows that guard/catch is meant to solve a nesting problem (just like guard/else was meant to solve one), and it preserves the idea that the else/catch clause must exit the outer scope, which is very important to the meaning of `guard`.<br></div>
<div><br></div>
<div>I agree with the proposal authors that mix-and-match guard/catch/else feels unwise. I see no reason why rewriting to repeat only the word `guard` (as in, `guard A catch { }; guard B else { }` instead of `guard A, B catch { } else { }`) is onerous enough to justify a syntax that is clearly harder to reason about.<br></div>
</div>
<div><div style="font-family:Arial;"><br></div>
<div defang_data-gmailquote="yes"><div style="font-family:Arial;">On Wed, Jul 5, 2017 at 2:25 PM, Soroush Khanlou via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt;</span> wrote:<br></div>
<blockquote defang_data-gmailquote="yes" style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left: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;"><div style="font-family:Arial;">Jon — we explored allowing users to mix and match optional unwrapping and error catching in the same guard, but found that it was ultimately pretty confusing. We think that guard/else and guard/catch should be two totally different components. Dave’s email lays out the two best approaches, and the “Alternatives Considered” section of the proposal goes into why those alternatives were ultimately rejected.<br></div>
<div><div><div><div style="font-family:Arial;"><br></div>
<div><blockquote type="cite"><div>On Jul 5, 2017, at 2:09 PM, Dave DeLong via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br></div>
<div style="font-family:Arial;"><br></div>
<div><div style="word-wrap:break-word;"><div style="font-family:Arial;">Soroush’s proposal has the idea that maybe we could do multiple blocks for this scenario, like so:<br></div>
<div><br></div>
<div><span class="font" style="font-family:Menlo"><span class="size" style="font-size:11px">guard try something(), let thing = optionalThing catch {</span></span><br></div>
<div><span class="font" style="font-family:Menlo"><span class="size" style="font-size:11px">&nbsp; &nbsp; // try something() failed</span></span><br></div>
<div><span class="font" style="font-family:Menlo"><span class="size" style="font-size:11px">} else {</span></span><br></div>
<div><span class="font" style="font-family:Menlo"><span class="size" style="font-size:11px">&nbsp; &nbsp; // the let-binding failed</span></span><br></div>
<div><span class="font" style="font-family:Menlo"><span class="size" style="font-size:11px">}</span></span><br></div>
<div><br></div>
<div>🤔 Alternatively, what if the “error” captured was optional in this scenario?<br></div>
<div><br></div>
<div><span class="font" style="font-family:Menlo"><span class="size" style="font-size:11px">guard try something(), let thing = optionalThing catch {</span></span><br></div>
<div><span class="font" style="font-family:Menlo"><span class="size" style="font-size:11px">&nbsp; &nbsp; if let error = error {</span></span><br></div>
<div><span class="font" style="font-family:Menlo"><span class="size" style="font-size:11px">&nbsp; &nbsp; &nbsp; &nbsp; // the try call failed</span></span><br></div>
<div><span class="font" style="font-family:Menlo"><span class="size" style="font-size:11px">&nbsp; &nbsp; } else {</span></span><br></div>
<div><span class="font" style="font-family:Menlo"><span class="size" style="font-size:11px">&nbsp; &nbsp; &nbsp; &nbsp; // the optional binding failed</span></span><br></div>
<div><span class="font" style="font-family:Menlo"><span class="size" style="font-size:11px">&nbsp; &nbsp; }</span></span><br></div>
<div><span class="font" style="font-family:Menlo"><span class="size" style="font-size:11px">}</span></span><br></div>
<div><br></div>
<div>Dave<br></div>
<div><div style="font-family:Arial;"><br></div>
<div><blockquote type="cite"><div>On Jul 5, 2017, at 12:00 PM, Jon Shier via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br></div>
<div style="font-family:Arial;"><br></div>
<div><div style="word-wrap:break-word;"><div style="font-family:Arial;"><span style="white-space:pre-wrap;"></span>I didn’t think I was going to like it but I really do. My only concern, which isn’t really a deal breaker, is what it would look like to chain multiple try and let statement in the same guard. Unless that scenario works well I don’t think you could convince others. i.e. In the case where I have:<br></div>
<div><br></div>
<div>guard try something(), let thing = optionalThing catch { }<br></div>
<div><br></div>
<div>What happens when the let fails? No implicit error?<br></div>
<div><br></div>
<div><br></div>
<div><br></div>
<div>Jon<br></div>
<div><br></div>
<div><div style="font-family:Arial;"><br></div>
<div><div><blockquote type="cite"><div>On Jul 5, 2017, at 1:30 PM, Soroush Khanlou via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br></div>
<div style="font-family:Arial;"><br></div>
<div><div style="word-wrap:break-word;"><div>I’d like to propose a guard/catch construct to the language. It would allow code to use throwing functions and handle errors fully, without straying from a happy path. do/catch can be a bit heavy-handed sometimes, and it would be nice to be able to handle throwing functions without committing to all the nesting and ceremony of do/catch.<br></div>
<div><br></div>
<div>Full proposal, which discusses all the corner cases and alternatives:<br></div>
<div><a href="https://gist.github.com/khanlou/8bd9c6f46e2b3d94f0e9f037c775f5b9">https://gist.github.com/<wbr>khanlou/<wbr>8bd9c6f46e2b3d94f0e9f037c775f5<wbr>b9</a><br></div>
<div><br></div>
<div>Looking forward to feedback!<br></div>
<div><br></div>
<div>Soroush<br></div>
</div>
<div style="font-family:Arial;">______________________________<wbr>_________________<br></div>
<div style="font-family:Arial;">swift-evolution mailing list<br></div>
<div style="font-family:Arial;"><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br></div>
<div style="font-family:Arial;"><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br></div>
</div>
</blockquote></div>
<div style="font-family:Arial;"><br></div>
</div>
</div>
</div>
<div style="font-family:Arial;">______________________________<wbr>_________________<br></div>
<div style="font-family:Arial;">swift-evolution mailing list<br></div>
<div style="font-family:Arial;"><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br></div>
<div style="font-family:Arial;"><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br></div>
</div>
</blockquote></div>
<div style="font-family:Arial;"><br></div>
</div>
</div>
<div style="font-family:Arial;">______________________________<wbr>_________________<br></div>
<div style="font-family:Arial;">swift-evolution mailing list<br></div>
<div style="font-family:Arial;"><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br></div>
<div style="font-family:Arial;"><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br></div>
</div>
</blockquote></div>
<div style="font-family:Arial;"><br></div>
</div>
</div>
</div>
</div>
<div style="font-family:Arial;"><br></div>
<div style="font-family:Arial;">______________________________<wbr>_________________<br></div>
<div style="font-family:Arial;"> swift-evolution mailing list<br></div>
<div style="font-family:Arial;"> <a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br></div>
<div style="font-family:Arial;"> <a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br></div>
<div style="font-family:Arial;"> <br></div>
</blockquote></div>
</div>
<div><u>_______________________________________________</u><br></div>
<div>swift-evolution mailing list<br></div>
<div><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br></div>
<div><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div>
</blockquote><div style="font-family:Arial;"><br></div>
</body>
</html>