<html><head></head><body><div>I like the bar `|` variation, but I do think the control value should be out front, otherwise the ? reads as an optional to my mind, whereas the former comes across as the beginning of a ternary (which this is effectively an extension of). </div><div>The bar variation feels Haskell-y in a satisfying way, and also has the added benefit of clearly delimiting the effective "range" of the multiary. <br><br><div class="acompli_signature">Alex Popov Jr.<br>Principal iOS developer | Shelfie<br><a dir="ltr" href="http://www.shelfie.com" x-apple-data-detectors="true" x-apple-data-detectors-type="link" x-apple-data-detectors-result="1">www.shelfie.com</a> | @getshelfie</div><br></div><br><br><br>
<div class="gmail_quote">On Wed, Jan 6, 2016 at 8:35 PM -0800, "Paul Ossenbruggen via swift-evolution" <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="3D"ltr"">
<meta http-equiv="Content-Type" content="text/html charset=utf-8">Hi Charles,<div class=""><br class=""></div><div class="">Chris, already said he did not like ? being used for ternary because it was already used for optionals. I think because of historical precedent it may be acceptable here. I have tried combos earlier with ! and got no support, admittedly not with the same usage as yours. </div><div class=""><br class=""></div><div class="">Do you really find it confusing not having a separator there? It is essentially a switch case without the word “case”. In my model the colon only indicates the “else” or “default” case, the other cases are separated by commas or whitespace. With my email taking the Swift Book examples and converting it from statement to expression form, I did not find any of them confusing, well maybe the first one, which found vowels and consonants, but that did not look that great in statement form either. . </div><div class=""><br class=""></div><div class="">if so maybe the | would be better as the separator because it would not change the switch like syntax:</div><div class=""><br class=""></div><div class=""><div class="" style="font-family: Menlo; margin: 0px; line-height: normal; color: rgb(0, 132, 0);"><div class="" style="margin: 0px; line-height: normal;"><span class="" style="color: rgb(187, 44, 162);">let</span><span class="" style="color: rgb(0, 0, 0);"> numberSymbol: </span><span class="" style="color: rgb(112, 61, 170);">Character</span><span class="" style="color: rgb(0, 0, 0);"> = </span><span class="" style="color: rgb(209, 47, 27);">"</span><span class="" style="line-height: normal; font-family: 'PingFang SC'; color: rgb(209, 47, 27);">三</span><span class="" style="color: rgb(209, 47, 27);">"</span><span class="" style="color: rgb(0, 0, 0);"> </span>// Simplified Chinese for the number 3</div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="color: rgb(187, 44, 162);">let</span> possibleIntegerValue:<span class="" style="color: rgb(112, 61, 170);">Int</span>? = <span class="" style="color: rgb(79, 129, 135);">numberSymbol</span> ?</div><div class="" style="margin: 0px; line-height: normal;"> | <span class="" style="color: rgb(209, 47, 27);">"1"</span>, <span class="" style="color: rgb(209, 47, 27);">"</span><span class="" style="line-height: normal; font-family: 'Courier New'; color: rgb(209, 47, 27);">١</span><span class="" style="color: rgb(209, 47, 27);">"</span>, <span class="" style="color: rgb(209, 47, 27);">"</span><span class="" style="line-height: normal; font-family: 'PingFang SC'; color: rgb(209, 47, 27);">一</span><span class="" style="color: rgb(209, 47, 27);">"</span>, <span class="" style="color: rgb(209, 47, 27);">"</span><span class="" style="line-height: normal; font-family: Ayuthaya; color: rgb(209, 47, 27);">๑</span><span class="" style="color: rgb(209, 47, 27);">"</span>: <span class="" style="color: rgb(39, 42, 216);">1</span></div><div class="" style="margin: 0px; line-height: normal;"> | <span class="" style="color: rgb(209, 47, 27);">"2"</span>, <span class="" style="color: rgb(209, 47, 27);">"</span><span class="" style="line-height: normal; font-family: 'Courier New'; color: rgb(209, 47, 27);">٢</span><span class="" style="color: rgb(209, 47, 27);">"</span>, <span class="" style="color: rgb(209, 47, 27);">"</span><span class="" style="line-height: normal; font-family: 'PingFang SC'; color: rgb(209, 47, 27);">二</span><span class="" style="color: rgb(209, 47, 27);">"</span>, <span class="" style="color: rgb(209, 47, 27);">"</span><span class="" style="line-height: normal; font-family: Ayuthaya; color: rgb(209, 47, 27);">๒</span><span class="" style="color: rgb(209, 47, 27);">"</span>: <span class="" style="color: rgb(39, 42, 216);">2</span></div><div class="" style="margin: 0px; line-height: normal;"> | <span class="" style="color: rgb(209, 47, 27);">"3"</span>, <span class="" style="color: rgb(209, 47, 27);">"</span><span class="" style="line-height: normal; font-family: 'Courier New'; color: rgb(209, 47, 27);">٣</span><span class="" style="color: rgb(209, 47, 27);">"</span>, <span class="" style="color: rgb(209, 47, 27);">"</span><span class="" style="line-height: normal; font-family: 'PingFang SC'; color: rgb(209, 47, 27);">三</span><span class="" style="color: rgb(209, 47, 27);">"</span>, <span class="" style="color: rgb(209, 47, 27);">"</span><span class="" style="line-height: normal; font-family: Ayuthaya; color: rgb(209, 47, 27);">๓</span><span class="" style="color: rgb(209, 47, 27);">"</span>: <span class="" style="color: rgb(39, 42, 216);">3</span></div><div class="" style="margin: 0px; line-height: normal;"> | <span class="" style="color: rgb(209, 47, 27);">"4"</span>, <span class="" style="color: rgb(209, 47, 27);">"</span><span class="" style="line-height: normal; font-family: 'Courier New'; color: rgb(209, 47, 27);">٤</span><span class="" style="color: rgb(209, 47, 27);">"</span>, <span class="" style="color: rgb(209, 47, 27);">"</span><span class="" style="line-height: normal; font-family: 'PingFang SC'; color: rgb(209, 47, 27);">四</span><span class="" style="color: rgb(209, 47, 27);">"</span>, <span class="" style="color: rgb(209, 47, 27);">"</span><span class="" style="line-height: normal; font-family: Ayuthaya; color: rgb(209, 47, 27);">๔</span><span class="" style="color: rgb(209, 47, 27);">"</span>: <span class="" style="color: rgb(39, 42, 216);">4</span></div><div class="" style="margin: 0px; line-height: normal;"> | <span class="" style="color: rgb(187, 44, 162);">_</span> : <span class="" style="color: rgb(187, 44, 162);">nil</span></div><div class="" style="margin: 0px; line-height: normal;"><br class=""></div><div class="" style="margin: 0px; line-height: normal; color: rgb(79, 129, 135);"><span class="" style="color: rgb(187, 44, 162);">if</span><span class="" style="color: rgb(0, 0, 0);"> </span><span class="" style="color: rgb(187, 44, 162);">let</span><span class="" style="color: rgb(0, 0, 0);"> integerValue = </span>possibleIntegerValue<span class="" style="color: rgb(0, 0, 0);"> {</span></div><div class="" style="margin: 0px; line-height: normal; color: rgb(209, 47, 27);"><span class="" style="color: rgb(0, 0, 0);"> </span><span class="" style="color: rgb(61, 29, 129);">print</span><span class="" style="color: rgb(0, 0, 0);">(</span>"The integer value of <span class="" style="color: rgb(0, 0, 0);">\</span>(<span class="" style="color: rgb(79, 129, 135);">numberSymbol</span>) is <span class="" style="color: rgb(0, 0, 0);">\</span>(<span class="" style="color: rgb(0, 0, 0);">integerValue</span>)."<span class="" style="color: rgb(0, 0, 0);">)</span></div><div class="" style="margin: 0px; line-height: normal;">} <span class="" style="color: rgb(187, 44, 162);">else</span> {</div><div class="" style="margin: 0px; line-height: normal; color: rgb(209, 47, 27);"><span class="" style="color: rgb(0, 0, 0);"> </span><span class="" style="color: rgb(61, 29, 129);">print</span><span class="" style="color: rgb(0, 0, 0);">(</span>"An integer value could not be found for <span class="" style="color: rgb(0, 0, 0);">\</span>(<span class="" style="color: rgb(79, 129, 135);">numberSymbol</span>)."<span class="" style="color: rgb(0, 0, 0);">)</span></div><div class="" style="margin: 0px; line-height: normal;">}</div></div><div class="" style="font-family: Menlo; margin: 0px; line-height: normal; color: rgb(0, 132, 0);">// prints "The integer value of <span class="" style="line-height: normal; font-family: 'PingFang SC';">三</span> is 3.”</div></div><div class=""><br class=""></div><div class="">But I still don’t see it a necessary. perhaps that would allow removal of the parenthesis and I think this would get rejected as not looking very Swift like. Also single line form which isn’t bad:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Arial; color: rgb(96, 96, 96);" class=""><b class=""><span class="" style="white-space: pre;">        </span>let val = color ? </b><span style="color: rgb(227, 36, 0);" class=""><b class="">.Red:</b></span><b class=""> 0xFF0000 | </b><span style="color: rgb(227, 36, 0);" class=""><b class="">.Green:</b></span><b class=""> 0x00FF00 | </b><b class=""> </b><span style="color: rgb(227, 36, 0);" class=""><b class="">.Blue:</b></span><b class=""> 0x0000FF</b><b class=""> | </b><span style="color: rgb(227, 36, 0);" class=""><b class="">_:</b></span><b class=""> 0xFFFFFF</b></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Arial; color: rgb(96, 96, 96);" class=""><br class=""></div><div>But still not sure the | adds that much.</div><div><br class=""></div><div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Arial; color: rgb(96, 96, 96);" class=""><b class=""><span class="" style="white-space: pre;">        </span>let val = color ? </b><span style="color: rgb(227, 36, 0);" class=""><b class="">.Red:</b></span><b class=""> 0xFF0000, </b><span style="color: rgb(227, 36, 0);" class=""><b class="">.Green:</b></span><b class=""> 0x00FF00, </b><b class=""> </b><span style="color: rgb(227, 36, 0);" class=""><b class="">.Blue:</b></span><b class=""> 0x0000FF, </b><b class=""> </b><span style="color: rgb(227, 36, 0);" class=""><b class="">_:</b></span><b class=""> 0xFFFFFF</b></div><div class=""><br class=""></div>Or this is without the commas is still readable but maybe a little harder:</div><div><br class=""></div><div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Arial; color: rgb(96, 96, 96);" class=""><b class=""><span class="" style="white-space: pre;">        </span>let val = color ? </b><span style="color: rgb(227, 36, 0);" class=""><b class="">.Red:</b></span><b class=""> 0xFF0000 </b><span style="color: rgb(227, 36, 0);" class=""><b class="">.Green:</b></span><b class=""> 0x00FF00 </b><b class=""> </b><span style="color: rgb(227, 36, 0);" class=""><b class="">.Blue:</b></span><b class=""> 0x0000FF </b><b class=""> </b><span style="color: rgb(227, 36, 0);" class=""><b class="">_:</b></span><b class=""> 0xFFFFFF</b></div><div class=""><b class=""><br class=""></b></div></div><div>One other thing, I would still prefer the control value inside the brace rather than out front, but I see that most people still want it out front and since it would be a breaking change for ternary, I have kind of backed off it but I think this is still clearer because the control value is not floating out in front. </div><div><br class=""></div><div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Arial; color: rgb(96, 96, 96);" class=""><b class=""><span class="" style="white-space: pre;">        </span>let val = ?(color, </b><span style="color: rgb(227, 36, 0);" class=""><b class="">.Red:</b></span><b class=""> 0xFF0000, </b><span style="color: rgb(227, 36, 0);" class=""><b class="">.Green:</b></span><b class=""> 0x00FF00, </b><b class=""> </b><span style="color: rgb(227, 36, 0);" class=""><b class="">.Blue:</b></span><b class=""> 0x0000FF, </b><b class=""> </b><span style="color: rgb(227, 36, 0);" class=""><b class="">_:</b></span><b class=""> 0xFFFFFF)</b></div><div class=""><b class=""><br class=""></b></div><blockquote type="cite" class=""><div class="">On Jan 6, 2016, at 7:06 PM, Charles Constant <<a href="mailto:charles@charlesism.com" class="">charles@charlesism.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class=""><div class=""><div style="font-size: 13px; margin: 0px; line-height: normal; font-family: Arial;" class=""><span style="font-family:arial,sans-serif;font-size:small" class="">> </span><span style="font-family:arial,sans-serif" class="">I see what you are trying to do, because of the colon being both used for switch cases and </span><br class=""></div></div></div><div class=""><span style="font-size:13px" class="">> separators for the ternary and so there needs to be a new character for each case. </span></div><div class=""><span style="font-size:13px" class="">> I am not sure that putting colons between each case is really necessary though.</span></div><div class=""><span style="font-size:13px" class=""><br class=""></span></div><div class="">Most of us (including you and I) like a form that starts with " let val = condition ? " like the existing ternary. Let's say a proposal like that gets accepted... I really believe "colons as separators" is the best idea in the case. Otherwise, it gets pretty confusing.. we'll have the existing ternary where a colon does one thing, and our new "extra ternary" where it does something else. </div><div class=""><br class=""></div><div class="">This is why I like colons (this won't make sense unless your email has rich text to show the colors): </div><div class=""><br class=""></div><div class=""><div class=""><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Arial; color: rgb(96, 96, 96);" class=""><b class=""><span class="" style="white-space:pre">        </span>let val = color ? </b></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Arial; color: rgb(96, 96, 96);" class=""><b class=""><span class="" style="white-space:pre">                </span></b><span style="color:rgb(227,36,0)" class=""><b class="">.Red !</b></span><b class=""> <span class="" style="white-space:pre">        </span>0xFF0000 : </b></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Arial; color: rgb(96, 96, 96);" class=""><b class=""><span class="" style="white-space:pre">                </span></b><span style="color:rgb(227,36,0)" class=""><b class="">.Green !</b></span><b class=""> <span class="" style="white-space:pre">        </span>0x00FF00 : </b></div><p style="font-size:13px;margin:0px;line-height:normal;font-family:Arial" class="">
</p><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Arial; color: rgb(96, 96, 96);" class=""><b class=""><span class="" style="white-space:pre">                </span></b><span style="color:rgb(227,36,0)" class=""><b class="">_ !</b></span><b class=""> <span class="" style="white-space:pre">                </span>0xFFFFFF</b></div></div></div><div class=""><b class=""><br class=""></b></div><div class="">... no syntax here different from the existing except the addition " <span style="font-family:Arial;font-size:13px;color:rgb(227,36,0)" class=""><b class="">.Red !</b></span><span style="font-size:13px;font-family:Arial" class=""> </span>". As for the exclamation... Swift already uses an exclamation for a billion other things, which is unfortunate. But the same can be said of "?" and that's already used in a "switch" without causing confusion. </div><div class=""><span style="font-size:13px" class=""><br class=""></span></div><div class=""><div style="font-size: 13px; margin: 0px; line-height: normal; font-family: Arial;" class="">> To point 1: I agree it needs a new name, I came up with the “demux expression” </div><div style="font-size: 13px; margin: 0px; line-height: normal; font-family: Arial;" class="">> but maybe there is a better name.<br class=""></div></div><div class=""><span style="font-size:13px" class=""><br class=""></span></div><div class="">Has anyone suggested "multiary expression" yet? Seems in keeping with "ternary"<br class=""></div><div class=""><span style="font-size:13px" class=""><br class=""></span></div><div class=""><span style="font-size:13px" class=""><br class=""></span></div><div class=""><span style="font-size:13px" class=""><br class=""></span></div><div class=""><span style="font-size:13px" class=""><br class=""></span></div><div class=""><span style="font-size:13px" class=""><br class=""></span></div><div class=""><br class=""></div></div>
</div></blockquote></div><br class=""></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=CmwAv3oRa0AH4Hd1bWC6X-2BzbhPqo1YEo6mPHEujr90tf49b8rhKLPXuV92GY4NdUv4EG9itS3QSiqCXCA5jemelN2qOs-2F4BIemFG8-2FpbpO4FbXPfJwt1gr0bu5Q3HdQjNqAqqgUI1XMBcxoIY1OlylGGKhcBiT2F9Z-2FBf0zXtMFkX5wArZFZ4J5m5ynlzaWlgXjYSf8k581306L5F8XFBc06d-2FNPH4sHMZk7eUU-2Byp8-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;">
</div>
</blockquote>
</div>
</body></html>