<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 9 févr. 2016 à 01:00, Thorsten Seitz <<a href="mailto:tseitz42@icloud.com" class="">tseitz42@icloud.com</a>> a écrit :</div><br class="Apple-interchange-newline"><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: 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;" class=""><br class="Apple-interchange-newline"><br class="">Am 09.02.2016 um 01:51 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" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: 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;" class=""><div class=""><br class=""><div class=""><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=""><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 class="" style="background-color: rgba(255, 255, 255, 0);">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 class="" style="background-color: rgba(255, 255, 255, 0);"><br class=""></span></font></div><div class=""><font class=""><span class="" style="background-color: rgba(255, 255, 255, 0);">No new syntax needed for that.</span></font></div></div></div></blockquote><br class=""></div><div class="">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 style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: 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;" class=""><br class=""></div><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: 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="">I like :? too, btw.</span><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: 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;" class=""><br class=""><blockquote type="cite" class=""><div class=""><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(79, 129, 135);">str</span><span class="Apple-converted-space"> </span>= major ><span class="Apple-converted-space"> </span><span class="" style="color: rgb(39, 42, 216);">0</span><span class="Apple-converted-space"> </span>?<span class="Apple-converted-space"> </span><span class="" style="color: rgb(209, 47, 27);">"Major"</span><span class="Apple-converted-space"> </span>: minor ><span class="Apple-converted-space"> </span><span class="" style="color: rgb(39, 42, 216);">0</span><span class="Apple-converted-space"> </span>?<span class="Apple-converted-space"> </span><span class="" style="color: rgb(209, 47, 27);">"Minor"</span><span class="Apple-converted-space"> </span>:<span class="Apple-converted-space"> </span><span class="" style="color: rgb(209, 47, 27);">"None"</span></div><div class=""><span class="" style="color: rgb(209, 47, 27);"><br class=""></span></div></div><div class="">which is ill suited for switch case but doable.</div></div></blockquote><div class=""><br class=""></div>No need to press something into switch which does not fit.</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: 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;" class="">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></blockquote><div><br class=""></div>Of course, it’s not about what should remain unmentioned (saying it out loud three time may cause that thread to come back and haunt us).</div><div>But while the proposal can be mainly read as:</div><div><br class=""></div><div>- provide a special case-list closure (aka pattern matching partial function dedicated to switch) and expand implicit returns support for this closure type only.</div><div><br class=""></div><div>it could also be read as</div><div><br class=""></div><div>- expand the implicit returns support for all closure, allow such closure to skip the switch keyword; be the case list (aka pattern matching partial function).</div><div><br class=""></div><div>I do think that safely expanding the implicit returns support in either the dedicated closure or the general closure would be roughly the same.</div><div><br class=""></div><div>I’m not sure where I stand on the switch-less case-list closure, but I am afraid that providing such dedicated closure syntax may set a precedent and cause others to want yet another dedicated closure syntax for their own goal; how do we consider a special closure syntax as acceptable, how many of them are too many. This is why, I’m looking at it from a wide angle view; an expanded implicit returns support safely done could benefit other general cases. Doing this as a first step, will miss 50% of this proposal (still need to use switch ($0)), but the overall use case goal will still be achieved; being able to do something like; let something = condition ? data1 : data2; for more complex scenarios.</div><div><br class=""></div><div>I’m having trouble following my own train of thought, but I think it’s leading me toward having the "safely expanded implicit returns » portion extracted as its own proposal for general purpose, which this proposal can then rely on.</div><div><br class=""><blockquote type="cite" class=""><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: 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;" class=""><br class=""><blockquote type="cite" class=""><div class=""><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">switch</span><span class="Apple-converted-space"> </span>(major,minor) {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="Apple-converted-space"> </span><span class="" style="color: rgb(187, 44, 162);">case</span><span class="Apple-converted-space"> </span>(<font color="#bb2ca2" class="">_</font>,<span class="Apple-converted-space"> </span><span class="" style="color: rgb(187, 44, 162);">_</span>)<span class="Apple-converted-space"> </span><span class="" style="color: rgb(187, 44, 162);">where</span><span class="Apple-converted-space"> </span>major ><span class="Apple-converted-space"> </span><span class="" style="color: rgb(39, 42, 216);">0</span>:<span class="Apple-converted-space"> </span><span class="" style="color: rgb(79, 129, 135);">str</span>=<span class="" style="color: rgb(209, 47, 27);">"Major"</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="Apple-converted-space"> </span><span class="" style="color: rgb(187, 44, 162);">case</span><span class="Apple-converted-space"> </span>(<span class="" style="color: rgb(187, 44, 162);">_</span>,<span class="Apple-converted-space"> </span><font color="#bb2ca2" class="">_</font>)<span class="Apple-converted-space"> </span><span class="" style="color: rgb(187, 44, 162);">where</span><span class="Apple-converted-space"> </span>minor ><span class="Apple-converted-space"> </span><span class="" style="color: rgb(39, 42, 216);">0</span>:<span class="Apple-converted-space"> </span><span class="" style="color: rgb(79, 129, 135);">str</span>=<span class="" style="color: rgb(209, 47, 27);">"Minor"</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="Apple-converted-space"> </span><span class="" style="color: rgb(187, 44, 162);">default</span>:<span class="Apple-converted-space"> </span><span class="" style="color: rgb(79, 129, 135);">str</span>=<span class="" style="color: rgb(209, 47, 27);">"None"</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> }</div></div></div></blockquote><div class=""><br class=""></div>Rewriting a little bit I don't think switch looks that bad even for your example:</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: 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;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: 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;" class=""><div class="" style="margin: 0px; line-height: normal;"><font class=""><span style="background-color: rgba(255, 255, 255, 0);" class=""><span class="">switch</span> (major,minor) {</span></font></div><div class="" style="margin: 0px; line-height: normal;"><font class=""><span style="background-color: rgba(255, 255, 255, 0);" class=""><span class="">case</span> <font class="">_</font> <span class="">where</span> major > <span class="">0</span>: <span class="">"Major"</span></span></font></div><div class="" style="margin: 0px; line-height: normal;"><font class=""><span style="background-color: rgba(255, 255, 255, 0);" class=""><span class="">case</span> <span class="">_ </span><span class="">where</span> minor > <span class="">0</span>: <span class="">"Minor"</span></span></font></div><div class="" style="margin: 0px; line-height: normal;"><font class=""><span style="background-color: rgba(255, 255, 255, 0);" class=""><span class="">default</span>: <span class="">"None"</span></span></font></div><div class="" style="margin: 0px; line-height: normal;"><font class=""><span style="background-color: rgba(255, 255, 255, 0);" class="">}</span></font></div></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: 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;" class=""><br class=""><div class=""><div class=""><div class=""><br class=""></div><div class=""></div></div></div></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: 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;" class=""></div><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: 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;" class=""><div class=""><div class=""><div class=""><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 class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(79, 129, 135);">str</span><span class="Apple-converted-space"> </span>= match(major,minor){<span class="Apple-converted-space"> </span><span class="" style="color: rgb(187, 44, 162);">if</span><span class="Apple-converted-space"> </span>$0 ><span class="Apple-converted-space"> </span><span class="" style="color: rgb(39, 42, 216);">0</span><span class="Apple-converted-space"> </span>{<span class="Apple-converted-space"> </span><span class="" style="color: rgb(209, 47, 27);">"Major"</span><span class="Apple-converted-space"> </span>}<span class="Apple-converted-space"> </span><span class="" style="color: rgb(187, 44, 162);">else</span><span class="Apple-converted-space"> </span><span class="" style="color: rgb(187, 44, 162);">if</span><span class="Apple-converted-space"> </span>$1 ><span class="Apple-converted-space"> </span><span class="" style="color: rgb(39, 42, 216);">0</span><span class="Apple-converted-space"> </span>{<span class="Apple-converted-space"> </span><span class="" style="color: rgb(209, 47, 27);">"Minor"</span><span class="Apple-converted-space"> </span>}<span class="Apple-converted-space"> </span><span class="" style="color: rgb(187, 44, 162);">else</span><span class="Apple-converted-space"> </span>{<span class="Apple-converted-space"> </span><span class="" style="color: rgb(209, 47, 27);">"None"</span><span class="Apple-converted-space"> </span>} }</div></div></div></div><div class=""><br class=""></div></div></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: 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;" class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: 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;" class="">Making `if` into an expression (which would be a requirementbhere) has been more or less ruled out by Chris Lattner. </div></div></blockquote><div><br class=""></div>I recall some oppositions early on, but I do not recall if it was before the thread move into closure territory.</div><div>Don’t forget my example here as two big if:</div><div>- if we generalized the implicit return done safely to any closure.</div><div>- if we try to call the closure passing the parameters with the only (to be) available prefix syntax<br class=""><br class="">Dany</div><div><br class=""><blockquote type="cite" class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: 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;" class=""><br class=""></div><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: 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;" class=""><div class=""><div class=""><div class=""><div class=""><br class=""></div><div class="">or using normal inline closure calls:</div><div class=""><br class=""></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(79, 129, 135);">str</span><span class="Apple-converted-space"> </span>= {<span class="Apple-converted-space"> </span><span class="" style="color: rgb(187, 44, 162);">if</span><span class="Apple-converted-space"> </span>$0 ><span class="Apple-converted-space"> </span><span class="" style="color: rgb(39, 42, 216);">0</span><span class="Apple-converted-space"> </span>{<span class="Apple-converted-space"> </span><span class="" style="color: rgb(209, 47, 27);">"Major"</span><span class="Apple-converted-space"> </span>}<span class="Apple-converted-space"> </span><span class="" style="color: rgb(187, 44, 162);">else</span><span class="Apple-converted-space"> </span><span class="" style="color: rgb(187, 44, 162);">if</span><span class="Apple-converted-space"> </span>$1 ><span class="Apple-converted-space"> </span><span class="" style="color: rgb(39, 42, 216);">0</span><span class="Apple-converted-space"> </span>{<span class="Apple-converted-space"> </span><span class="" style="color: rgb(209, 47, 27);">"Minor"</span><span class="Apple-converted-space"> </span>}<span class="Apple-converted-space"> </span><span class="" style="color: rgb(187, 44, 162);">else</span><span class="Apple-converted-space"> </span>{<span class="Apple-converted-space"> </span><span class="" style="color: rgb(209, 47, 27);">"None"</span><span class="Apple-converted-space"> </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 class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(79, 129, 135);">str</span><span class="Apple-converted-space"> </span>= (major,minor) -> {<span class="Apple-converted-space"> </span><span class="" style="color: rgb(187, 44, 162);">if</span><span class="Apple-converted-space"> </span>$0 ><span class="Apple-converted-space"> </span><span class="" style="color: rgb(39, 42, 216);">0</span><span class="Apple-converted-space"> </span>{<span class="Apple-converted-space"> </span><span class="" style="color: rgb(209, 47, 27);">"Major"</span><span class="Apple-converted-space"> </span>}<span class="Apple-converted-space"> </span><span class="" style="color: rgb(187, 44, 162);">else</span><span class="Apple-converted-space"> </span><span class="" style="color: rgb(187, 44, 162);">if</span><span class="Apple-converted-space"> </span>$1 ><span class="Apple-converted-space"> </span><span class="" style="color: rgb(39, 42, 216);">0</span><span class="Apple-converted-space"> </span>{<span class="Apple-converted-space"> </span><span class="" style="color: rgb(209, 47, 27);">"Minor"</span><span class="Apple-converted-space"> </span>}<span class="Apple-converted-space"> </span><span class="" style="color: rgb(187, 44, 162);">else</span><span class="Apple-converted-space"> </span>{<span class="Apple-converted-space"> </span><span class="" style="color: rgb(209, 47, 27);">"None"</span><span class="Apple-converted-space"> </span>} }</div></div><div class=""><br class=""></div></div><div class="">Maybe it’s just me, but the match function feels a bit weird, in the first version.</div></div></div></blockquote><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: 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;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: 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;" class="">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 style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: 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;" class=""><br class=""></div></blockquote></div><br class=""></body></html>