<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="">Yeah I believe we did discuss this a bit. I like it.&nbsp;<div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 15, 2015, at 1:29 PM, Thorsten Seitz &lt;<a href="mailto:tseitz42@icloud.com" class="">tseitz42@icloud.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="content-type" content="text/html; charset=utf-8" class=""><div dir="auto" class=""><div class=""></div><div class="">If we keep the ternary operator as "if-expression" for its succinctness,&nbsp;</div><div class="">I'd like to refresh the proposal of I-don't-remember-whom of having a similar</div><div class="">switch-expression:</div><div class=""><br class=""></div><div class="">let x = color ?</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; case .Red: red</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; case .Green: green</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; default: black</div><div class=""><br class=""></div><div class="">The "case"s nicely separate the expressions and they even have colons ;-)</div><div class="">I'd keep the "case" keywords for three reasons: first, parsing, second, similarity&nbsp;</div><div class="">to the switch statement and third, readability (otherwise it would be really difficult</div><div class="">to discern case patterns from results).</div><div class=""><br class=""></div><div class="">-Thorsten&nbsp;</div><div class=""><br class="">Am 15.12.2015 um 11:34 schrieb Al Skipp via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt;:<br class=""><br class=""></div><blockquote type="cite" class=""><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 15 Dec 2015, at 06:41, 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=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Agreed, I was thinking to I really want turn something that was 2 characters into 10 and will I really be happy with that at the end of the day. A properly formatted ternary can be quite easy to read, it is when people get sloppy and try to cram too much into one expression that they get really hard to follow. For example,</span><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class=""><font color="#222426" face="Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, sans-serif" size="2" class=""><span class="" style="white-space: pre;">&nbsp; &nbsp; return (a&lt;b) ? (b&lt;c) ? b : (a&lt;c) ? c : a : (a&lt;c) ? a : (b&lt;c) ? c : b;</span></font></div><font color="#222426" face="Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, sans-serif" size="2" class=""><span class="" style="white-space: pre;"><br class="Apple-interchange-newline"></span></font></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><font color="#222426" size="2" class=""><span class="" style="white-space: pre;">If formatted like this becomes easier follow the logic (at least to me):</span></font></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span class="" style="color: rgb(34, 36, 38); font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; font-size: small; white-space: pre;"><br class=""></span></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span class="" style="color: rgb(34, 36, 38); font-size: small; white-space: pre;"><font face="Monaco" class="">    return a &lt; b</font></span></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span class="" style="color: rgb(34, 36, 38); font-size: small; white-space: pre;"><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>? b &lt; c&nbsp;</font></span></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span class="" style="color: rgb(34, 36, 38); font-size: small; white-space: pre;"><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>  ? b&nbsp;</font></span></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span class="" style="color: rgb(34, 36, 38); font-size: small; white-space: pre;"><font face="Monaco" class="">          : a &lt; c&nbsp;</font></span></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span class="" style="color: rgb(34, 36, 38); font-size: small; white-space: pre;"><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>     ? c&nbsp;</font></span></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span class="" style="color: rgb(34, 36, 38); font-size: small; white-space: pre;"><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>     : a&nbsp;</font></span></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span class="" style="color: rgb(34, 36, 38); font-size: small; white-space: pre;"><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>: a &lt; c&nbsp;</font></span></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span class="" style="color: rgb(34, 36, 38); font-size: small; white-space: pre;"><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>  ? a&nbsp;</font></span></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span class="" style="color: rgb(34, 36, 38); font-size: small; white-space: pre;"><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>  : b &lt; c &nbsp;</font></span></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span class="" style="color: rgb(34, 36, 38); font-size: small; white-space: pre;"><font face="Monaco" class="">             ? c&nbsp;</font></span></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span class="" style="color: rgb(34, 36, 38); font-size: small; white-space: pre;"><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>     : b</font></span></div></div></blockquote><div class=""><br class=""></div><div class="">I’m happy to make use of the ternary operator, but never in a nested fashion. It looks neat and succinct on first glance, but is quite impenetrable to read. I don’t think there’s a way to make such nested expressions easily comprehensible. Nested ‘if/else/then’ expressions will be equally bewildering.</div><div class=""><br class=""></div><div class="">On a purely stylistic level I think simple, ‘if/then/else’ expressions, would have a more Swift vibe to them than the ternary operator. Well, that would be the case if it didn’t introduce the confusion between expressions and statements.</div><br class=""><blockquote type="cite" class=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><font color="#222426" size="2" class=""><span class="" style="white-space: pre;">I do still however like the Switch Expressions.</span></font></div></blockquote></div><br class=""><div class="">I agree. The Switch expression proposal is worth pursuing, it’s something I’d really like to see in the language. One concern I have is that it faces the same dilemma of the ‘if’ expression proposal, that is, how to make the distinction between a statement and an expression unambiguous?</div><div class=""><br class=""></div><div class="">Here’s a suggestion, it might be terrible (I’ve not had my third cup of tea of the morning yet), but how about a different keyword? I know, I feel guilty for the suggestion already, but here it is:</div><div class=""><br class=""></div><div class="">switch == statement</div><div class="">match == expression</div><div class=""><br class=""></div><div class="">The syntax you (@Paul) have already suggested for the feature wouldn’t change, but instead of ‘switch’, it’d use the ‘match’ keyword for the expression form. Good, bad, terrible? What do people think?</div><div class=""><br class=""></div><div class="">Al</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=1MXK54sosN3xru3iYcLt0oBZ2w20i49gyogXctgrspdYQ6Vhvwhr6aqfX7MC1JfuYFEnz-2FKcNFtbc7rRYi5lndFtMT-2FeeTngzopzC6q1V3BVwcg8H7XD-2Bpz-2FVrni-2BrQJcF90PRC9mBcIwvU3P8rOjzj9g2bPHUcYJyuzjAwevAxvsB0gAaB1HaI85QX8tumnqr8lwZtFGZnvPJuUhmohQrRYwtCeNI1g0PZ1y-2B-2B406A-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></blockquote><blockquote type="cite" class=""><div class=""><span class="">_______________________________________________</span><br class=""><span class="">swift-evolution mailing list</span><br class=""><span class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a></span><br class=""><span class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br class=""></div></blockquote></div></div></blockquote></div><br class=""></div></body></html>