<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=""><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=""></body></html>