<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=""><div class="">If at all possible, it’d be good to avoid adding new keywords, however if the keyword ‘then’ could enable 'if expressions’ and ‘switch expressions’, I’d be fully in favour.&nbsp;</div><div class=""><br class=""></div><div class="">Binding to a variable using a switch statement isn’t as elegant as it could be. The ability to define a ‘let’ variable and assigning a value later in a switch statement does help somewhat, but the examples below are very clear and elegant in my opinion. (I’d even question the necessity of the repetitive keyword ‘case’, but maybe that’s a step too far?)</div><div class=""><br class=""></div><div class="">Al</div><br class=""><div><blockquote type="cite" class=""><div class="">On 12 Dec 2015, at 07:15, Paul Ossenbruggen 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="">So adding “then”:&nbsp;<div class=""><br class=""></div><div class="">let v = if condition then “A” else “B”&nbsp;</div><div class=""><br class=""></div><div class="">fixes that ambiguity and “then” would help differentiate an expression from a statement. I think there is value to having them separate constructs (for details see earlier comments in this thread). Also it is nice not having the braces in the expression.&nbsp;</div><div class=""><br class=""></div><div class="">Perhaps, similarly, “then" indicates an expression as opposed to a statement:</div><div class=""><br class=""></div><div class="">let v = switch condition then case Red: 1, case Blue: 2, case Green: 3</div><div class=""><br class=""></div><div class="">One downside is it, It may add confusion as to when to add the “then” clause as people will have to know what an expression vs statement is, but I suppose that is true with a ternary operator as well, and this reads better than a ternary operator. This also provides a good way to do single line switch expressions.&nbsp;</div><div class=""><br class=""></div><div class="">for multiline:</div><div class=""><br class=""></div><div class="">let v = if condition&nbsp;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>then “A”&nbsp;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>else “B"</div><div class=""><br class=""></div><div class="">let v = switch condition then&nbsp;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>case .Red: 1,</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>case .Blue: 2,</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>case .Green: 3</div><div class=""><br class=""></div><div class="">or with multiple expressions:</div><div class=""><br class=""></div><div class="">let v = switch condition then&nbsp;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>case .Red: 1,</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>case .Blue: (if shade == .Dark then 4 else 2),</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>case .Green: 3</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><div class=""><blockquote type="cite" class=""><div class=""><br class=""></div><div class="">On Dec 11, 2015, at 8:57 PM, Chris Lattner 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=""><div class=""><blockquote type="cite" class=""><div class="">On Dec 11, 2015, at 5:36 PM, Andrey Tarantsov via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">How about:</div><div class=""><div class=""><br class="">let v = if condition then “A" else “B"<br class=""></div></div></blockquote><div class=""><br class=""></div><div class="">I don't think introducing a separate "then" keyword is a good idea, two subtly different kinds of IFs would be confusing.</div><div class=""><br class=""></div>I guess you meant:</div><div class=""><br class=""></div></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><div class="">let v = if condition { "A" } else { "B” }</div></div></blockquote></div></div></blockquote><br class=""></div><div class="">I don’t really want to wade into this discussion, but if A and B are intended to be *expressions* instead of an arbitrary sequence of statements|decls|exprs, then a more consistent syntax would be:</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>let v = if condition (A) else (b)&nbsp;</div><div class=""><br class=""></div><div class="">The immediate problem with that is that juxtaposition of two expressions (condition, and A [with or without parens]) will lead to immediate syntactic ambiguity.</div><div class=""><br class=""></div><div class="">-Chris</div><br class="">
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=emrIhnP1hIf76Foxxv4NNJQX-2FWhcznESwKBSwD1MEwy2nS8v48IWpyQDQIXo1e9V6bZ72y4tqc12q9XsoeC3W2792hCXoiRIr-2BbgFCgzyT1zzQkar1O40NXJZqW9OH4VpRlFg5Uk9wEaobDVD87aURHSWk-2FqZxSVZCGHOBqVSsnhGd1kOd6HLh04mTjneaWLUz2K-2Ftbl1gZv4x52WmGjLTim9d-2FmNG8-2B7tBDoCdHebc-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=""></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=beeSmh5kY-2BJ166T9jAm-2BjJ0Ntx7b5Xyuqmzlt3vqHGSiNp176dWK1AeeLHK-2Bnx5QcZeKpZMiUgYkW5iG-2BunraRCKIDzJvEuGCM5u7xynxlBvAoSH32IOLgTaM9F7Mak2cFnjKXJ9iLl3SyPQ0apSEVC3wrpz9zCWf7j48-2BMMpohO1JBYa82tf2YvwOXwr4T-2FtJMCyIshZEhjfLAR2FXnYi4YEHSBmsTzeZj8UvbZ-2Bsk-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>