<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div></div><div>I like these expressions with "then" and without braces.</div><div><br></div><div>What about using "then" for statements as well?</div><div><br></div><div>If condition then {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; ...</div><div>} else {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; ...</div><div>}</div><div><br>Am 12.12.2015 um 08:15 schrieb Paul Ossenbruggen via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt;:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html charset=utf-8">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><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">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=1MXK54sosN3xru3iYcLt0oBZ2w20i49gyogXctgrspfVV6w3yyYIj8cM2hlC28EDGCVSN6ELFKtWVn1qx6vvDGrPLmLBz-2Bz3NVpY3BChk3duX2rRCyfIaGX4XLk3WenyKTp1Mh5m4rET2mq9a1qXZFDnYd1rvy9uh7O3gD73Pq1AB5j2OfFqWSUtpBfEFAsmAd3-2FuWS1dcE8S29hCrYKPEB6uOzOQctyattaZJh-2Feyk-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;">

</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></body></html>