<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="">Been thinking a bit:<div class=""><br class=""></div><div class="">Perhaps a new expression is in order. “Pick” this has a form like this. Param is a selector &nbsp;This only allows expressions&nbsp;</div><div class=""><br class=""></div><div class="">It has two forms:&nbsp;</div><div class=""><br class=""></div><div class="">To replace ternary:&nbsp;</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="color: rgb(187, 44, 162);" class="">let</span>&nbsp;x = pick val from&nbsp;<span style="color: rgb(209, 47, 27);" class="">"abc"</span>,&nbsp;<span style="color: rgb(209, 47, 27);" class="">"cdef"</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 14px;" class="">To replace switch expressions. The cases follows existing rules for switch cases.&nbsp;</div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="color: rgb(187, 44, 162);" class="">let</span>&nbsp;y = pick val from cases .Red:&nbsp;<span style="color: rgb(39, 42, 216);" class="">1</span>, .Green:&nbsp;<span style="color: rgb(39, 42, 216);" class="">2</span>, .Blue:&nbsp;<span style="color: rgb(39, 42, 216);" class="">3</span></div></div><div class=""><span style="color: rgb(39, 42, 216);" class=""><br class=""></span></div><div class="">This keeps the notion of expressions and statements quite separate. It avoids syntax confusion. It reads clear. It is fairy concise. It uses a straight forward pattern for both forms of expression.&nbsp;</div><div class=""><br class=""></div><div class="">- Paul</div><div class=""><br class=""></div><div><blockquote type="cite" class=""><div class="">On Dec 15, 2015, at 2:06 PM, Charles Constant via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class=""><div class="">+1 bigtime for the assignment via Switch proposal</div><div class=""><br class=""></div><div class="">I think someone here made the argument, I can't remember who, that it would be confusing for beginners. I think exactly the opposite.&nbsp;</div><div class=""><br class=""></div><div class="">Once a new programmer has learned how to write a normal Switch statement, they'll be able to "leverage" the same concept and map values using the Switch assignment. Some might even try it on their on own, through experimentation, to see if it will work. It's such a pleasant experience when you try something in a language that seems consistent with what you already know, and discover "cool, it works!"</div><div class=""><br class=""></div><div class="">At the moment, the alternatives are, what, using a dict to map values? trying to shoehorn a corrsponding set of values into an enum? using the existing switch statement (pretty verbose in Swift, due to "let" scope etc)? In my own Swift code, I have encountered situations, frequently, where I wished I had an equivalent to a ternary condition that handled more than two values. Chaining multiple ternary conditions together is unreadable. This proposed Switch assignment expression would take care of that.&nbsp;</div><div class=""><br class=""></div><div class="">Definitely has my vote!</div><div class=""><br class=""></div><div class="gmail_extra"></div></div></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=emrIhnP1hIf76Foxxv4NNJQX-2FWhcznESwKBSwD1MEwxiM0wxa3Eidlta26BoCkLrzEEM5gqpjcqwPHugOGYVJHSh0Cjz6WEph83xry-2BaIR0W-2BKDcO90DaStUsyF4iNqood42gQEqgflqw3Fj-2FmcGmt1jP83W0hWaer61T4MeYAxfNwGCNPrBIQq5Enp0s7XgYWXO2b1v4iMMuQ1IJj7zUuWxD2B7iN4zwx9avyCtGYo-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;" class="">
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>