<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="">Another idea is put the conditional at the beginning:<div class=""><br class=""></div><div class="">let foo if conditional then = 10 else = 20</div><div class=""><br class=""></div><div class="">But that requires an additional keyword to separate out the conditional but might read better. </div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 6, 2015, at 2:14 AM, possen p <<a href="mailto:possen@gmail.com" class="">possen@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div 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) </div><div class=""><br class=""></div>So, 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 // produces an error. </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. </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 </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.. </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;"> 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;"> funcWithSideEffectsThatReturnsString() </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. </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: </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;"> = 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;"> = dosomethingelse() </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 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 better. </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: </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 = </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. </div><div class=""><br class=""></div><div class=""><font face="menlo, consolas, courier new, monospace, sans-serif" class="">Note that these are still chainable expressions: </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 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 </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></div></div></blockquote></div><br class=""></div></body></html>