<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div></div><div><br></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></blockquote><div><br></div>I like :? too, btw.<div><br><blockquote type="cite"><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></blockquote><div><br></div>No need to press something into switch which does not fit.</div><div>The proposal is not about using switch for everything and it is not about replacing the ternary operator. It is more about making a switch expression available.</div><div><br><blockquote type="cite"><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> (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></div></blockquote><div><br></div>Rewriting a little bit I don't think switch looks that bad even for your example:</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="">switch</span>&nbsp;(major,minor) {</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>&nbsp;<font class="">_</font>&nbsp;<span class="">where</span>&nbsp;major &gt;&nbsp;<span class="">0</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);"><span class="">case</span>&nbsp;<span class="">_&nbsp;</span><span class="">where</span>&nbsp;minor &gt;&nbsp;<span class="">0</span>:&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);"><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);">}</span></font></div></div><div><br><div><div><div class=""><br class=""></div><div class=""></div></div></div></div><div></div><blockquote type="cite"><div><div><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></div><div><br></div></div></blockquote><br><div>Making `if` into an expression (which would be a requirementbhere) has been more or less ruled out by Chris Lattner.&nbsp;</div><div><br></div><div><br></div><blockquote type="cite"><div><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></div></blockquote><div><br></div><div>I agree. That's why it is accompanied by the partial function closure syntax which effectively results in a switch or rather match expression.</div><div><br></div><div>-Thorsten&nbsp;</div></body></html>