<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">(I originally posted as possen p and since hopefully fixed that)&nbsp;</div><div class=""><br class=""></div>So,&nbsp;As Kevin Ballard and Ole Bergman pointed out, making a regular “if” an expression has some major complications. Having the potential to return different object types in a strictly typed language will not be easy. Also what to do if the if does not have an else. The ternary operator does not allow the if/else results of different types. In Python doing an expression with if/else is not a problem because it will let you return different types, this is legal, (which makes sense for Python):<div class=""><br class=""></div><div class="">val = 10 if p == 5 else “abc"</div><div class=""><br class=""></div><div class="">it will not however let you omit the else part:</div><div class=""><br class=""></div><div class="">val = 10 if False &nbsp;// produces an error.&nbsp;</div><div class=""><br class=""></div><div class="">so it appears if you assign to an expression in Python it will require the else part. So it is different than a regular if.&nbsp;</div><div class=""><br class=""></div><div class="">So I ask, is making the regular “if" an expression truly desired for Swift? I do see other languages doing it, but it does seem a bit odd to assign from any “if”. In my original proposal I was suggesting that assignment is done like this:</div><div class=""><br class=""></div><div class="">let val = 10 else 40 if p == 5&nbsp;</div><div class=""><br class=""></div><div class="">In this it is very similar to the ternary expression in that else part is required and both types must match, and has improved readability. This is overloading the if/else keywords to provide essentially the same thing as ternary operators..&nbsp;</div><div class=""><br class=""></div><div class="">The following from Kevin Ballard's email:</div><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><div dir="ltr" class=""><blockquote style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;" class=""><div class=""><span class="font" style="font-family: menlo, consolas, 'courier new', monospace, sans-serif;">let foo = if condition {</span><span class="font" style="font-family: menlo, consolas, 'courier new', monospace, sans-serif;"></span><br class=""></div><div class=""><span class="font" style="font-family: menlo, consolas, 'courier new', monospace, sans-serif;">&nbsp; &nbsp; funcWithSideEffectsThatReturnsInt()</span><span class="font" style="font-family: menlo, consolas, 'courier new', monospace, sans-serif;"></span><br class=""></div><div class=""><span class="font" style="font-family: menlo, consolas, 'courier new', monospace, sans-serif;">} else {</span><span class="font" style="font-family: menlo, consolas, 'courier new', monospace, sans-serif;"></span><br class=""></div><div class=""><span class="font" style="font-family: menlo, consolas, 'courier new', monospace, sans-serif;">&nbsp; &nbsp;&nbsp;funcWithSideEffectsThatReturnsString()&nbsp;</span><br class=""></div><div class=""><span class="font" style="font-family: menlo, consolas, 'courier new', monospace, sans-serif;">}</span><br class=""></div></blockquote></div></blockquote></div><div class=""><div dir="ltr" class=""><blockquote style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;" class=""><div class=""><span class="font" style="font-family: menlo, consolas, 'courier new', monospace, sans-serif;"><br class=""></span></div><div class=""><span class="font" style="font-family: menlo, consolas, 'courier new', monospace, sans-serif;">I find it is hard to tell that the two results are returning a value. To me it looks like it is either ignoring the return value or is returning void.&nbsp;</span></div><div class=""><span style="font-family: menlo, consolas, 'courier new', monospace, sans-serif;" class=""><br class=""></span></div><div class=""><font face="menlo, consolas, courier new, monospace, sans-serif" class="">Maybe emphasizing the assignment would help as below does not have return values in the method names:&nbsp;</font></div><div class=""><br class=""></div><div class=""><div class=""><div dir="ltr" class=""><blockquote style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;" class=""><div dir="ltr" class=""><blockquote style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;" class=""><div class=""><span class="font" style="font-family: menlo, consolas, 'courier new', monospace, sans-serif;">let foo if condition {</span><span class="font" style="font-family: menlo, consolas, 'courier new', monospace, sans-serif;"></span><br class=""></div><div class=""><span class="font" style="font-family: menlo, consolas, 'courier new', monospace, sans-serif;">&nbsp; &nbsp; =&nbsp;dosomething()</span><span class="font" style="font-family: menlo, consolas, 'courier new', monospace, sans-serif;"></span></div><div class=""><span class="font" style="font-family: menlo, consolas, 'courier new', monospace, sans-serif;">} else {</span><span class="font" style="font-family: menlo, consolas, 'courier new', monospace, sans-serif;"></span><br class=""></div><div class=""><span class="font" style="font-family: menlo, consolas, 'courier new', monospace, sans-serif;">&nbsp; &nbsp; =&nbsp;dosomethingelse()&nbsp;</span></div><div class=""><span class="font" style="font-family: menlo, consolas, 'courier new', monospace, sans-serif;">}</span></div></blockquote></div><div class=""><div dir="ltr" class=""><blockquote style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;" class=""><div class=""><span class="font" style="font-family: menlo, consolas, 'courier new', monospace, sans-serif;"><br class=""></span></div></blockquote></div></div></blockquote></div></div></div><div class=""><font face="menlo, consolas, courier new, monospace, sans-serif" class="">putting the = after&nbsp;the else shows that it is returning a value for the let clause. It also helps emphasize that the return types must match and I think looks&nbsp;better.&nbsp;</font></div><div class=""><font face="menlo, consolas, courier new, monospace, sans-serif" class=""><br class=""></font></div><div class=""><font face="menlo, consolas, courier new, monospace, sans-serif" class="">Going back to my proposal with the = suggestion:&nbsp;</font></div><div class=""><font face="menlo, consolas, courier new, monospace, sans-serif" class=""><br class=""></font></div><div class=""><div class=""><font face="menlo, consolas, courier new, monospace, sans-serif" class="">let foo = dosomething() else =&nbsp;</font><span style="font-family: menlo, consolas, 'courier new', monospace, sans-serif;" class="">dosomethingelse</span><font face="menlo, consolas, courier new, monospace, sans-serif" class="">() if condition</font></div></div><div class=""><br class=""></div><div class="">this really shows that the let variable is being assigned.&nbsp;</div><div class=""><br class=""></div><div class=""><font face="menlo, consolas, courier new, monospace, sans-serif" class="">Note that these are still&nbsp;chainable expressions:&nbsp;</font></div><div class=""><font face="menlo, consolas, courier new, monospace, sans-serif" class=""><br class=""></font></div><div class=""><font face="menlo, consolas, courier new, monospace, sans-serif" class="">var foo = ((10 else = 40 if p == 5) else = (15 else = 14 if p == 10) if p == 4)</font></div><div class=""><font face="menlo, consolas, courier new, monospace, sans-serif" class=""><br class=""></font></div><div class=""><font face="menlo, consolas, courier new, monospace, sans-serif" class="">It&nbsp;may be good to make the space optional after the else:</font></div><div class=""><font face="menlo, consolas, courier new, monospace, sans-serif" class=""><br class=""></font></div><div class=""><div class=""><font face="menlo, consolas, courier new, monospace, sans-serif" class="">var foo = ((10 else= 40 if p == 5) else= (15 else= 14 if p == 10) if p == 4)</font></div></div><div class=""><font face="menlo, consolas, courier new, monospace, sans-serif" class=""><br class=""></font></div><div class="">- Paul&nbsp;</div></blockquote></div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""><div class=""><br class=""></div></div></body></html>