<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div></div><div>The ternary expression can also be accomplished by this match:</div><div><br></div><div><div class="" style="margin: 0px; line-height: normal;"><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);"><span class="">&nbsp; &nbsp; str = match(</span>(major &gt; 0, minor &gt; 0)) {</span></font></div><div class="" style="margin: 0px; line-height: normal;"><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span class="">case</span>&nbsp;(true,&nbsp;<span class="">_</span>):&nbsp;<span class="">"Major"</span></span></font></div><div class="" style="margin: 0px; line-height: normal;"><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span class="">case</span>&nbsp;(<span class="">_</span>,&nbsp;true):&nbsp;<span class="">"Minor"</span></span></font></div><div class="" style="margin: 0px; line-height: normal;"><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span class="">default</span>:&nbsp;<span class="">"None"</span></span></font></div><div class="" style="margin: 0px; line-height: normal;"><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">&nbsp; &nbsp; }</span></font></div></div><div><br></div><div>Or using "cases":</div><div><br></div><div><div class="" style="margin: 0px; line-height: normal;"><span style="background-color: rgba(255, 255, 255, 0);"><span class="">&nbsp; &nbsp; str = match(</span>(major &gt; 0, minor &gt; 0)) {</span></div><div class="" style="margin: 0px; line-height: normal;"><span style="background-color: rgba(255, 255, 255, 0);">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span class="">cases</span>&nbsp;(true,&nbsp;<span class="">_</span>):&nbsp;<span class="">"Major",</span></span><span style="background-color: rgba(255, 255, 255, 0);">&nbsp;(</span><span class="" style="background-color: rgba(255, 255, 255, 0);">_</span><span style="background-color: rgba(255, 255, 255, 0);">,&nbsp;true):&nbsp;</span><span class="" style="background-color: rgba(255, 255, 255, 0);">"Minor"</span></div><div class="" style="margin: 0px; line-height: normal;"><span style="background-color: rgba(255, 255, 255, 0);">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span class="">default</span>:&nbsp;<span class="">"None"</span></span></div><div class="" style="margin: 0px; line-height: normal;"><span style="background-color: rgba(255, 255, 255, 0);">&nbsp; &nbsp; }</span></div></div><div><br></div><div>At least the former version is to me clearer than the original ternary expression.</div><div>While the switch expression "forces" you to format the code whereas a ternary operator doesn't.</div><div><br></div><div>"correctly" formatted:</div><div><br></div><div><div class="" style="margin: 0px; line-height: normal;"><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);"><span class="">&nbsp; &nbsp; str</span>&nbsp;= major &gt;&nbsp;<span class="">0</span>&nbsp;?&nbsp;<span class="">"Major"</span>&nbsp;:</span></font></div><div class="" style="margin: 0px; line-height: normal;"><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;minor &gt;&nbsp;<span class="">0</span>&nbsp;?&nbsp;<span class="">"Minor"</span>&nbsp;:&nbsp;<span class="">"None"</span></span></font></div></div><div><br></div><div>But as Thorsten has already said the proposal is not about removing the ternary operator.</div><div><br></div><div>- Maximilian</div><div><br>Am 09.02.2016 um 01:51 schrieb Dany St-Amant 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"><br class=""><div><blockquote type="cite" class=""><div class="">Le 8 févr. 2016 à 10:54, Thorsten Seitz &lt;<a href="mailto:tseitz42@icloud.com" class="">tseitz42@icloud.com</a>&gt; a écrit :</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=""><br class=""></div><div class=""><br class="">Am 07.02.2016 um 16:47 schrieb Dany St-Amant 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=""><span class="">Assuming this implicit return part of this proposal get generalized, could we instead of the dedicated match function have a generic way to feed the parameters to the closure at the start, where it would make sense for the desired switch usage.</span><br class=""><span class=""></span><br class=""><span class="">let str:String = (state) -&gt; { switch $0 { case .Cold: "Too Cold"; case .Hot: "Too Hot"; default: "Just right" } }</span></blockquote><br class=""><div class="">That's easy, just use the match() function from the proposal:</div><div class=""><br class=""></div><div class=""><div class=""><font class=""><span style="background-color: rgba(255, 255, 255, 0);" class="">let str:String = match(state) { switch $0 { case .Cold: "Too Cold"; case .Hot: "Too Hot"; default: "Just right" } }</span></font></div></div><div class=""><font class=""><span style="background-color: rgba(255, 255, 255, 0);" class=""><br class=""></span></font></div><div class=""><font class=""><span style="background-color: rgba(255, 255, 255, 0);" class="">No new syntax needed for that.</span></font></div></div></div></blockquote><br class=""></div><div>As/if the implicit returns is generalized, I feel that match is bit out of place in the for nested if. I should have provided an example to clarify my thought. Here’s one, where the :? do a better job, but this thread has its origin in came people not liking this sometime cryptic operator (which I like to use)</div><div><br class=""></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp;&nbsp;<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">str</span> = major &gt; <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0</span> ? <span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"Major"</span> : minor &gt; <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0</span> ? <span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"Minor"</span> : <span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"None"</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class=""><br class=""></span></div></div><div>which is ill suited for switch case but doable.</div><div><br class=""></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp;&nbsp;<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">switch</span>&nbsp;(major,minor) {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">case</span> (<font color="#bb2ca2" class="">_</font>, <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">_</span>) <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">where</span> major &gt; <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0</span>: <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">str</span>=<span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"Major"</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">case</span> (<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">_</span>, <font color="#bb2ca2" class="">_</font>) <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">where</span> minor &gt; <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0</span>: <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">str</span>=<span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"Minor"</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">default</span>: <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">str</span>=<span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"None"</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; }</div><div class=""><br class=""></div><div class="">Assuming that the implicit returns is generalized to all closures (and even functions like getter), of course only for the one matching my safety rule (in short single statement/function call/exhaustive if or switch). The if &nbsp;can be express as, using the new global match function:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp;&nbsp;<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">str</span> = match(major,minor){ <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">if</span> $0 &gt; <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0</span> { <span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"Major"</span> } <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">else</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">if</span> $1 &gt; <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0</span> { <span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"Minor"</span> } <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">else</span> { <span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"None"</span> } }</div></div><div class=""><br class=""></div><div class="">or using normal inline closure calls:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp;&nbsp;<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">str</span> = { <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">if</span> $0 &gt; <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0</span> { <span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"Major"</span> } <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">else</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">if</span> $1 &gt; <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0</span> { <span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"Minor"</span> } <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">else</span> { <span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"None"</span> } }(major,minor)</div></div><div class=""><br class=""></div><div class="">versus the feeding I wonder about:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp;&nbsp;<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">str</span> = (major,minor) -&gt; { <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">if</span> $0 &gt; <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0</span> { <span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"Major"</span> } <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">else</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">if</span> $1 &gt; <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0</span> { <span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"Minor"</span> } <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">else</span> { <span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"None"</span> } }</div></div><div class=""><br class=""></div></div><div>Maybe it’s just me, but the match function feels a bit weird, in the first version.</div><div><br class=""></div><div>Dany</div><div><br class=""></div><br class=""></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>