<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=""> str = match(</span>(major > 0, minor > 0)) {</span></font></div><div class="" style="margin: 0px; line-height: normal;"><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);"> <span class="">case</span> (true, <span class="">_</span>): <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);"> <span class="">case</span> (<span class="">_</span>, true): <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);"> <span class="">default</span>: <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);"> }</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=""> str = match(</span>(major > 0, minor > 0)) {</span></div><div class="" style="margin: 0px; line-height: normal;"><span style="background-color: rgba(255, 255, 255, 0);"> <span class="">cases</span> (true, <span class="">_</span>): <span class="">"Major",</span></span><span style="background-color: rgba(255, 255, 255, 0);"> (</span><span class="" style="background-color: rgba(255, 255, 255, 0);">_</span><span style="background-color: rgba(255, 255, 255, 0);">, true): </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);"> <span class="">default</span>: <span class="">"None"</span></span></div><div class="" style="margin: 0px; line-height: normal;"><span style="background-color: rgba(255, 255, 255, 0);"> }</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=""> str</span> = major > <span class="">0</span> ? <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);"> minor > <span class="">0</span> ? <span class="">"Minor"</span> : <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 <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>>:<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 <<a href="mailto:tseitz42@icloud.com" class="">tseitz42@icloud.com</a>> 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 <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>>:<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) -> { 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=""> <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">str</span> = major > <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 > <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=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">switch</span> (major,minor) {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <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 > <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=""> <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 > <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=""> <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=""> }</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 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=""> <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 > <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 > <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=""> <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 > <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 > <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=""> <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">str</span> = (major,minor) -> { <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">if</span> $0 > <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 > <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>