Pick is interesting but how do you chain more that one pick/from together?<div><br></div><div>I thought about just just dropping the if.</div><div><br></div>let result = bool then 1 else bool then 2 else 3<div><br></div><div>Or going back to the python style. </div><div><br></div><div>let result = 1 where bool else where bool 2 else 3<br><div><br></div><div>But you are right, can't beat just having two characters. Specially when the Elvis operator is in every other major c based language. </div><div><br></div><div>Perhaps this is just a like ! as a negation character, once you learn the differences then u are set for other languages as well. </div><div><br></div><div>It would be nice to be able to bind expressions so that the actual logic of the ?: is not lost. </div><div><br></div><div>let result = if (long_boolexpresion, </div><div> longerBoolexoression, </div><div> anotherboolExpression ) </div><div> $0 then "a" else $1 && $2 then "b" else "c"<span></span><br><div><br><br>On Tuesday, December 15, 2015, Paul Ossenbruggen via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">I think pick…from may address many of the negatives listed by Chris. with the if..then..else approach.<div><br></div><div><blockquote type="cite"><span style="float:none;display:inline!important">The closest proposal I’ve seen is the “if cond then value1 else value2” syntax, however that has serious (IMO) problems:</span><br></blockquote><br><blockquote type="cite"><span style="float:none;display:inline!important">- It is substantially more verbose than ?:, so much so that it obscures the logic that was trying to be captured. Simple things like this become swallowed in syntax:</span><br><span style="float:none;display:inline!important"> let x = cond ? 4 : 8</span><br><span style="float:none;display:inline!important"> let x = if cond then 4 else 8</span><br></blockquote><div><br></div>this suggestion would still be longer, you can’t beat 2 chars. It is shorter than if..then..else though. Not sure there are any good options that can beat the conciseness of the ternary without replacing it with more syntax.</div><div><br></div><div><div style="word-wrap:break-word"><div><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">let</span> x = pick cond from <font color="#d12f1b">4</font>, <span style="color:rgb(209,47,27)">8</span></div></div></div><div><div style="word-wrap:break-word"><div><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="color:rgb(209,47,27)"><br></span></div></div></div></div><blockquote type="cite"><br><span style="float:none;display:inline!important">- Because it looks like an if statement, people will end up writing it like:</span><br><br><span style="float:none;display:inline!important">let x = if cond then</span><br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span><span style="float:none;display:inline!important">some_long_expression</span><br><span style="white-space:pre-wrap">        </span><span style="float:none;display:inline!important"> else</span><br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span><span style="float:none;display:inline!important">some_other_long_expression</span><br></blockquote><div><br></div><div><blockquote type="cite"><span style="float:none;display:inline!important"> - it only accepts expressions, not statements. The way it is flowed makes it look like a statement.</span><br><span style="float:none;display:inline!important"> - It is now force indenting a lot, which just looks weird and isn’t precedented in Swift.</span></blockquote><br></div><div>By having a new keyword, we can define the format and there is no prior connotation with it. </div><br><blockquote type="cite"><br><span style="float:none;display:inline!important">When this happens, we now have new problems: </span><br><span style="float:none;display:inline!important"> - At a glance, it “looks” like an if statement, but it is semantically different.</span><br></blockquote><div><br></div>Since it is a new it will always look like something that handles expressions only. </div><div><div><br></div><div>Also this pick…from statement can be extended to handle switch expressions as well. So it is consistent way to do different expressions based upon an input. </div><div><br></div><div>Some downsides: </div><div>new keyword</div><div>no prior history with other programming languages.</div><div><br></div><div><br></div><div><div><blockquote type="cite"><div>On Dec 15, 2015, at 4:31 PM, Paul Ossenbruggen <<a href="javascript:_e(%7B%7D,'cvml','possen@gmail.com');" target="_blank">possen@gmail.com</a>> wrote:</div><br><div><div style="word-wrap:break-word">Been thinking a bit:<div><br></div><div>Perhaps a new expression is in order. “Pick” this has a form like this. Param is a selector This only allows expressions </div><div><br></div><div>It has two forms: </div><div><br></div><div>To replace ternary: </div><div><br></div><div><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">let</span> x = pick val from <span style="color:rgb(209,47,27)">"abc"</span>, <span style="color:rgb(209,47,27)">"cdef"</span></div><div style="margin:0px;line-height:normal;font-family:Menlo;min-height:14px"><br></div><div style="margin:0px;line-height:normal;font-family:Menlo;min-height:14px">To replace switch expressions. The cases follows existing rules for switch cases. </div><div style="margin:0px;line-height:normal;font-family:Menlo;min-height:14px"><br></div><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">let</span> y = pick val from cases .Red: <span style="color:rgb(39,42,216)">1</span>, .Green: <span style="color:rgb(39,42,216)">2</span>, .Blue: <span style="color:rgb(39,42,216)">3</span></div></div><div><span style="color:rgb(39,42,216)"><br></span></div><div>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. </div><div><br></div><div>- Paul</div><div><br></div><div><blockquote type="cite"><div>On Dec 15, 2015, at 2:06 PM, Charles Constant via swift-evolution <<a href="javascript:_e(%7B%7D,'cvml','swift-evolution@swift.org');" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br><div><div dir="ltr"><div><div>+1 bigtime for the assignment via Switch proposal</div><div><br></div><div>I think someone here made the argument, I can't remember who, that it would be confusing for beginners. I think exactly the opposite. </div><div><br></div><div>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><br></div><div>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. </div><div><br></div><div>Definitely has my vote!</div><div><br></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="min-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">
_______________________________________________<br>swift-evolution mailing list<br><a href="javascript:_e(%7B%7D,'cvml','swift-evolution@swift.org');" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div></blockquote></div><br></div></div></blockquote></div><br></div></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=OWK4tSasaK2n-2FQIIcS9Ug-2FuFXG-2BJ3z6cFMLgm306hDcd45MQptT9erZgtrBVO57JH2apRT5Ssez8uGFCFFDjVaRJLoVtHp-2BQdbqU0p1LC2-2FsFfBJt2ErQHt5z5iMuJO8kAK061t99W-2FyZ-2BeXo4DWXa7fRa4jyVdL3KCuVeKLXrWfRXvdxv6jIPDZ895vHHH0ZHuChE1oCFV6BYI3o2nRp7C-2FFYvsQLgHsPH-2FzgvGefA-3D" alt="" width="1" height="1" border="0" style="min-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">
</div>
</blockquote></div></div></div>