<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Well, it turns out, I was testing it on already established values. The first of the following two examples works but the second does not.</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(186, 45, 162);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">switch</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> (</span><span style="font-variant-ligatures: no-common-ligatures" class="">true</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">, y: </span><span style="font-variant-ligatures: no-common-ligatures" class="">false</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">) {</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(186, 45, 162);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">case</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> (</span><span style="font-variant-ligatures: no-common-ligatures" class="">true</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">, y: </span><span style="font-variant-ligatures: no-common-ligatures" class="">false</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">): </span><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" class="">print</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"tf"</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">)</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(186, 45, 162);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">default</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">: </span><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" class="">print</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"nope"</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">)</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo; min-height: 21px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> testTuple2 = (</span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">true</span><span style="font-variant-ligatures: no-common-ligatures" class="">, </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">false</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo; min-height: 21px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">switch</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">testTuple2</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> {</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">// error: tuple pattern element label 'y' must be '_'</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(186, 45, 162);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">case</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> (</span><span style="font-variant-ligatures: no-common-ligatures" class="">true</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">, y: </span><span style="font-variant-ligatures: no-common-ligatures" class="">false</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">): </span><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" class="">print</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"tf"</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">)</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(186, 45, 162);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">default</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">: </span><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" class="">print</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"nope"</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">)</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div></div><div class=""><br class=""></div><div class="">I think this gets a 95% Emily Litella (<a href="https://en.wikipedia.org/wiki/Emily_Litella" class="">https://en.wikipedia.org/wiki/Emily_Litella</a>). "Nevermind."</div><div class=""><br class=""></div><div class="">And thanks, Tony,</div><div class=""><br class=""></div><div class="">-- E</div><div class=""><br class=""></div><div class=""><br class=""></div><div><blockquote type="cite" class=""><div class="">On Jan 1, 2017, at 8:49 PM, Tony Allevato &lt;<a href="mailto:tony.allevato@gmail.com" class="">tony.allevato@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">The "after" example you posted seems to work already in Swift today. Is there something I'm missing?<div class=""><br class=""></div></div><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Sun, Jan 1, 2017 at 7:35 PM David Sweeris via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto" class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"><br class="gmail_msg">Sent from my iPhone</div></div><div dir="auto" class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg">On Jan 1, 2017, at 19:25, Erica Sadun via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br class="gmail_msg"><br class="gmail_msg"></div><blockquote type="cite" class="gmail_msg"><div class="gmail_msg">Was helping a friend with some code and got inspired. I decided to throw this on list to see if there's any traction.&nbsp;<div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><b class="gmail_msg">Idea</b>: Introduce optional argument labels to tuples in switch statements</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><b class="gmail_msg">Motivation</b>: Cases can be less readable when pattern matching tuples. Semantically sugared, optional argument labels could increase readability for complex `switch` statements by incorporating roles into cases.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Here's an example before:</div><div class="gmail_msg"><br class="gmail_msg"></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px" class="gmail_msg"><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg">fileprivate func chargeState(for battery: BatteryService)</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg">&nbsp; &nbsp; -&gt; ChargeState</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg">{</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg">&nbsp; &nbsp; switch (battery.state, battery.isCalculating) {</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg">&nbsp; &nbsp; case (.isACPowered, true):</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg">&nbsp; &nbsp; &nbsp; &nbsp; return .calculating(isDischarging: false)</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg">&nbsp; &nbsp; case (.isACPowered, _) where battery.isCharging:</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg">&nbsp; &nbsp; &nbsp; &nbsp; return .charging</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg">&nbsp; &nbsp; case (.isACPowered, _):</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg">&nbsp; &nbsp; &nbsp; &nbsp; return .acPower</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg">&nbsp; &nbsp; case (_, true):</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg">&nbsp; &nbsp; &nbsp; &nbsp; return .calculating(isDischarging: true)</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg">&nbsp; &nbsp; default:</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg">&nbsp; &nbsp; &nbsp; &nbsp; return .batteryPower</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg">&nbsp; &nbsp; }</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg">}</font></div></div></blockquote><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">and after:</div><div class="gmail_msg"><br class="gmail_msg"></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px" class="gmail_msg"><div class="gmail_msg"><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg">fileprivate func chargeState(for battery: BatteryService)</font></div></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg">&nbsp; &nbsp; -&gt; ChargeState</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg">{</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg">&nbsp; &nbsp; switch (battery.state, <b class="gmail_msg">calculating: battery.isCalculating</b>) {</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg">&nbsp; &nbsp; case (.isACPowered, <b class="gmail_msg">calculating: true</b>):</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg">&nbsp; &nbsp; &nbsp; &nbsp; return .calculating(isDischarging: false)</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg">&nbsp; &nbsp; case (.isACPowered, _) where battery.isCharging:</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg">&nbsp; &nbsp; &nbsp; &nbsp; return .charging</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg">&nbsp; &nbsp; case (.isACPowered, _):</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg">&nbsp; &nbsp; &nbsp; &nbsp; return .acPower</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg">&nbsp; &nbsp; case (_, <b class="gmail_msg">calculating: true</b>):</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg">&nbsp; &nbsp; &nbsp; &nbsp; return .calculating(isDischarging: true)</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg">&nbsp; &nbsp; default:</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg">&nbsp; &nbsp; &nbsp; &nbsp; return .</font><span style="font-family:Menlo" class="gmail_msg">batteryPower</span></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg">&nbsp; &nbsp; }</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg">}</font></div></div></blockquote><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">It's a pretty minor change, and I could see it being added to allow case statements to be more readable with a minimal change to the compiler. I also have a back-burnered proposal I intend to introduce in Phase 2 that would introduce Boolean raw value enumerations for flags.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Thoughts?</div></div></blockquote><br class="gmail_msg"></div><div dir="auto" class="gmail_msg"><div class="gmail_msg">I can't think of a reason not to do that... +1</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">- Dave Sweeris</div></div>_______________________________________________<br class="gmail_msg">
swift-evolution mailing list<br class="gmail_msg">
<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a><br class="gmail_msg">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="gmail_msg">
</blockquote></div>
</div></blockquote></div><br class=""></body></html>