<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="">On Feb 26, 2016, at 12:25 AM, Andrew Bennett &lt;<a href="mailto:cacoyi@gmail.com" class="">cacoyi@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hi Amir,<div class=""><br class=""></div><div class="">I put forward a proposal a short while ago that may allow you to achieve similar to what you want, it is here:</div><div class=""><br class=""></div><b class="">Declare variables in 'case' labels with multiple patterns</b><div class=""><a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160118/007431.html" target="_blank" class="">https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160118/007431.html</a><br class=""></div><div class=""><br class=""></div><div class=""><a href="https://github.com/apple/swift-evolution/pull/119" class="">https://github.com/apple/swift-evolution/pull/119</a><br class=""></div><div class=""><br class=""></div><div class=""><div class="">It would allow you to express your logic like this:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="color:rgb(187,44,162)" class="">&nbsp; switch</span> vehicle {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="color:rgb(187,44,162)" class="">&nbsp; case</span> .Car(<span style="color:rgb(187,44,162)" class="">let</span>&nbsp;color), .Motorcycle(<span style="color:rgb(187,44,162)" class="">let</span>&nbsp;color), .Helicopter(<span style="color:rgb(187,44,162)" class="">let</span>&nbsp;color):</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp;&nbsp;<span style="color:rgb(187,44,162)" class="">switch</span> color {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp;&nbsp;<span style="color:rgb(187,44,162)" class="">case</span> .Red: &nbsp; ...</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp;&nbsp;<span style="color:rgb(187,44,162)" class="">case</span> .Green: ...</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp;&nbsp;<span style="color:rgb(187,44,162)" class="">case</span> .Blue:&nbsp; ...</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp;&nbsp;}</div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">






</p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; }</div></div></div><div class=""><br class=""></div><div class="">That proposal seemed to be well received with no votes against, and after a few tweaks seemed to have support from the Swift team.</div><div class=""><br class=""></div><div class="">What do you think about that approach? It's not quite as concise as what you proposed but it can be generalised more easily, and handles pattern matching of cases where `color` may not be the only associated value.</div><div class=""><br class=""></div></div></div></blockquote><div><br class=""></div><div>I like both proposals, yours and mine. They both have their uses.</div><br class=""><blockquote type="cite" class=""><div class=""><div class="gmail_extra"><br class=""><div class="gmail_quote">On Wed, Feb 24, 2016 at 1:13 AM, Amir Michail via swift-evolution <span dir="ltr" class="">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><br class=""><div class=""><span class=""><blockquote type="cite" class=""><div class="">On Feb 23, 2016, at 7:27 AM, Taras Zakharko &lt;<a href="mailto:taras.zakharko@uzh.ch" target="_blank" class="">taras.zakharko@uzh.ch</a>&gt; wrote:</div><br class=""><div class=""><div style="word-wrap:break-word" class="">I think that other designs (e.g. using classes/structs/protocols) offer a much better solution for this particular problem<div class=""><br class=""></div></div></div></blockquote><div class=""><br class=""></div></span><div class="">That might be more work than just listing all the cases...</div><div class=""><div class="h5"><div class=""><br class=""></div><blockquote type="cite" class=""><div class=""><div style="word-wrap:break-word" class=""><div class=""><div class=""><blockquote type="cite" class=""><div class="">On 23 Feb 2016, at 13:17, Amir Michail via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class=""><div class=""><blockquote type="cite" style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><br class="">On Feb 22, 2016, at 10:11 PM, Brent Royal-Gordon &lt;<a href="mailto:brent@architechies.com" target="_blank" class="">brent@architechies.com</a>&gt; wrote:<br class=""><br class=""><blockquote type="cite" class="">For example:<br class=""><br class="">enum Color {<br class=""><span style="white-space:pre-wrap" class="">        </span>...<br class="">}<br class=""><br class="">enum Vehicle {<br class=""><span style="white-space:pre-wrap" class="">        </span>case Car(Color)<br class=""><span style="white-space:pre-wrap" class="">        </span>case Motorcycle(Color)<br class=""><span style="white-space:pre-wrap" class="">        </span>...<br class="">}<br class=""><br class="">switch vehicle {<br class=""><span style="white-space:pre-wrap" class="">        </span>case _(.Red): … // pattern match based on associated value only<br class="">}<br class=""></blockquote><br class="">As usual, Amir:<span class="">&nbsp;</span><br class=""><br class="">1. Why do you want this feature?<br class=""></blockquote><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important" class="">In this example, if there are many kinds of vehicles, it would be annoying to have to write a case for each one to match associated value .Red.</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><blockquote type="cite" style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><br class="">2. What's actually wrong with the status quo?<br class=""><br class=""></blockquote><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important" class="">What would that be for this example? Many cases?</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><blockquote type="cite" style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="">3. Can you talk about a non-toy example you've encountered where it would have made your code better?<br class=""><br class="">4. Can you talk about the proposed design in a little more detail? Are there weird edge cases, and how would you handle them? (In the case of this feature, here's one I see: Suppose you have two different associated value types but they both have a .Red case. What happens then?)<br class=""><br class="">A half-dozen-word subject line and a code example simply aren't enough to evaluate a proposal. Without knowing exactly what you're proposing and why you think it's a good idea, we can't really evaluate it properly.<br class=""><br class="">--<span class="">&nbsp;</span><br class="">Brent Royal-Gordon<br class="">Architechies<br class=""><br class=""></blockquote><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important" class="">_______________________________________________</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important" class="">swift-evolution mailing list</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important" class=""><a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a></span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important" class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span></div></blockquote></div><br class=""></div></div></div></blockquote></div></div></div><br class=""></div><br class="">_______________________________________________<br class="">
swift-evolution mailing list<br class="">
<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
<br class=""></blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></body></html>