<div dir="ltr"><div><div>Alex, </div><div><br></div><div>We know, from the traditional ternary, that a colon is going to satisfy the requirements of a separator, even when we want to chain.<br></div></div><div><br></div><div>Is this the case with bar "|"? To me, this doesn't bode well....<br></div><div><br></div><div>let a = b ? </div><div> 2 : 3 |</div><div> 4 : 5 |<br></div><div> _ : -1 </div><div> </div><div>Above, are we talking about a result of "3 [Bitwise OR] 4" or is the result "3 [SEPARATOR] 4"? I could be wrong, but I suspect in practise, it would be complicated to use, and probably not possible to chain. </div><div><br></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 6, 2016 at 9:10 PM, Alex Popov <span dir="ltr"><<a href="mailto:hello@alexpopov.ca" target="_blank">hello@alexpopov.ca</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><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>Alex Popov Jr.<br>Principal iOS developer | Shelfie<br><a dir="ltr" href="http://www.shelfie.com" target="_blank">www.shelfie.com</a> | @getshelfie</div><br></div><br><br><br>
<div class="gmail_quote"><div><div class="h5">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>
</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="3D"ltr""><div><div class="h5">
Hi Charles,<div><br></div><div>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><br></div><div>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><br></div><div>if so maybe the | would be better as the separator because it would not change the switch like syntax:</div><div><br></div><div><div style="font-family:Menlo;margin:0px;line-height:normal;color:rgb(0,132,0)"><div style="margin:0px;line-height:normal"><span style="color:rgb(187,44,162)">let</span><span style="color:rgb(0,0,0)"> numberSymbol: </span><span style="color:rgb(112,61,170)">Character</span><span style="color:rgb(0,0,0)"> = </span><span style="color:rgb(209,47,27)">"</span><span style="line-height:normal;font-family:'PingFang SC';color:rgb(209,47,27)">三</span><span style="color:rgb(209,47,27)">"</span><span style="color:rgb(0,0,0)"> </span>// Simplified Chinese for the number 3</div><div style="margin:0px;line-height:normal"><span style="color:rgb(187,44,162)">let</span> possibleIntegerValue:<span style="color:rgb(112,61,170)">Int</span>? = <span style="color:rgb(79,129,135)">numberSymbol</span> ?</div><div style="margin:0px;line-height:normal"> | <span style="color:rgb(209,47,27)">"1"</span>, <span style="color:rgb(209,47,27)">"</span><span style="line-height:normal;font-family:'Courier New';color:rgb(209,47,27)">١</span><span style="color:rgb(209,47,27)">"</span>, <span style="color:rgb(209,47,27)">"</span><span style="line-height:normal;font-family:'PingFang SC';color:rgb(209,47,27)">一</span><span style="color:rgb(209,47,27)">"</span>, <span style="color:rgb(209,47,27)">"</span><span style="line-height:normal;font-family:Ayuthaya;color:rgb(209,47,27)">๑</span><span style="color:rgb(209,47,27)">"</span>: <span style="color:rgb(39,42,216)">1</span></div><div style="margin:0px;line-height:normal"> | <span style="color:rgb(209,47,27)">"2"</span>, <span style="color:rgb(209,47,27)">"</span><span style="line-height:normal;font-family:'Courier New';color:rgb(209,47,27)">٢</span><span style="color:rgb(209,47,27)">"</span>, <span style="color:rgb(209,47,27)">"</span><span style="line-height:normal;font-family:'PingFang SC';color:rgb(209,47,27)">二</span><span style="color:rgb(209,47,27)">"</span>, <span style="color:rgb(209,47,27)">"</span><span style="line-height:normal;font-family:Ayuthaya;color:rgb(209,47,27)">๒</span><span style="color:rgb(209,47,27)">"</span>: <span style="color:rgb(39,42,216)">2</span></div><div style="margin:0px;line-height:normal"> | <span style="color:rgb(209,47,27)">"3"</span>, <span style="color:rgb(209,47,27)">"</span><span style="line-height:normal;font-family:'Courier New';color:rgb(209,47,27)">٣</span><span style="color:rgb(209,47,27)">"</span>, <span style="color:rgb(209,47,27)">"</span><span style="line-height:normal;font-family:'PingFang SC';color:rgb(209,47,27)">三</span><span style="color:rgb(209,47,27)">"</span>, <span style="color:rgb(209,47,27)">"</span><span style="line-height:normal;font-family:Ayuthaya;color:rgb(209,47,27)">๓</span><span style="color:rgb(209,47,27)">"</span>: <span style="color:rgb(39,42,216)">3</span></div><div style="margin:0px;line-height:normal"> | <span style="color:rgb(209,47,27)">"4"</span>, <span style="color:rgb(209,47,27)">"</span><span style="line-height:normal;font-family:'Courier New';color:rgb(209,47,27)">٤</span><span style="color:rgb(209,47,27)">"</span>, <span style="color:rgb(209,47,27)">"</span><span style="line-height:normal;font-family:'PingFang SC';color:rgb(209,47,27)">四</span><span style="color:rgb(209,47,27)">"</span>, <span style="color:rgb(209,47,27)">"</span><span style="line-height:normal;font-family:Ayuthaya;color:rgb(209,47,27)">๔</span><span style="color:rgb(209,47,27)">"</span>: <span style="color:rgb(39,42,216)">4</span></div><div style="margin:0px;line-height:normal"> | <span style="color:rgb(187,44,162)">_</span> : <span style="color:rgb(187,44,162)">nil</span></div><div style="margin:0px;line-height:normal"><br></div><div style="margin:0px;line-height:normal;color:rgb(79,129,135)"><span style="color:rgb(187,44,162)">if</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(187,44,162)">let</span><span style="color:rgb(0,0,0)"> integerValue = </span>possibleIntegerValue<span style="color:rgb(0,0,0)"> {</span></div><div style="margin:0px;line-height:normal;color:rgb(209,47,27)"><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(61,29,129)">print</span><span style="color:rgb(0,0,0)">(</span>"The integer value of <span style="color:rgb(0,0,0)">\</span>(<span style="color:rgb(79,129,135)">numberSymbol</span>) is <span style="color:rgb(0,0,0)">\</span>(<span style="color:rgb(0,0,0)">integerValue</span>)."<span style="color:rgb(0,0,0)">)</span></div><div style="margin:0px;line-height:normal">} <span style="color:rgb(187,44,162)">else</span> {</div><div style="margin:0px;line-height:normal;color:rgb(209,47,27)"><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(61,29,129)">print</span><span style="color:rgb(0,0,0)">(</span>"An integer value could not be found for <span style="color:rgb(0,0,0)">\</span>(<span style="color:rgb(79,129,135)">numberSymbol</span>)."<span style="color:rgb(0,0,0)">)</span></div><div style="margin:0px;line-height:normal">}</div></div><div style="font-family:Menlo;margin:0px;line-height:normal;color:rgb(0,132,0)">// prints "The integer value of <span style="line-height:normal;font-family:'PingFang SC'">三</span> is 3.”</div></div><div><br></div><div>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><br></div><div><div style="margin:0px;font-size:13px;line-height:normal;font-family:Arial;color:rgb(96,96,96)"><b><span style="white-space:pre-wrap">        </span>let val = color ? </b><span style="color:rgb(227,36,0)"><b>.Red:</b></span><b> 0xFF0000 | </b><span style="color:rgb(227,36,0)"><b>.Green:</b></span><b> 0x00FF00 | </b><b> </b><span style="color:rgb(227,36,0)"><b>.Blue:</b></span><b> 0x0000FF</b><b> | </b><span style="color:rgb(227,36,0)"><b>_:</b></span><b> 0xFFFFFF</b></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:Arial;color:rgb(96,96,96)"><br></div><div>But still not sure the | adds that much.</div><div><br></div><div><div style="margin:0px;font-size:13px;line-height:normal;font-family:Arial;color:rgb(96,96,96)"><b><span style="white-space:pre-wrap">        </span>let val = color ? </b><span style="color:rgb(227,36,0)"><b>.Red:</b></span><b> 0xFF0000, </b><span style="color:rgb(227,36,0)"><b>.Green:</b></span><b> 0x00FF00, </b><b> </b><span style="color:rgb(227,36,0)"><b>.Blue:</b></span><b> 0x0000FF, </b><b> </b><span style="color:rgb(227,36,0)"><b>_:</b></span><b> 0xFFFFFF</b></div><div><br></div>Or this is without the commas is still readable but maybe a little harder:</div><div><br></div><div><div style="margin:0px;font-size:13px;line-height:normal;font-family:Arial;color:rgb(96,96,96)"><b><span style="white-space:pre-wrap">        </span>let val = color ? </b><span style="color:rgb(227,36,0)"><b>.Red:</b></span><b> 0xFF0000 </b><span style="color:rgb(227,36,0)"><b>.Green:</b></span><b> 0x00FF00 </b><b> </b><span style="color:rgb(227,36,0)"><b>.Blue:</b></span><b> 0x0000FF </b><b> </b><span style="color:rgb(227,36,0)"><b>_:</b></span><b> 0xFFFFFF</b></div><div><b><br></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></div><div><div style="margin:0px;font-size:13px;line-height:normal;font-family:Arial;color:rgb(96,96,96)"><b><span style="white-space:pre-wrap">        </span>let val = ?(color, </b><span style="color:rgb(227,36,0)"><b>.Red:</b></span><b> 0xFF0000, </b><span style="color:rgb(227,36,0)"><b>.Green:</b></span><b> 0x00FF00, </b><b> </b><span style="color:rgb(227,36,0)"><b>.Blue:</b></span><b> 0x0000FF, </b><b> </b><span style="color:rgb(227,36,0)"><b>_:</b></span><b> 0xFFFFFF)</b></div><div><b><br></b></div><blockquote type="cite"><div>On Jan 6, 2016, at 7:06 PM, Charles Constant <<a href="mailto:charles@charlesism.com" target="_blank">charles@charlesism.com</a>> wrote:</div><br><div><div dir="ltr"><div><div><div style="font-size:13px;margin:0px;line-height:normal;font-family:Arial"><span style="font-family:arial,sans-serif;font-size:small">> </span><span style="font-family:arial,sans-serif">I see what you are trying to do, because of the colon being both used for switch cases and </span><br></div></div></div><div><span style="font-size:13px">> separators for the ternary and so there needs to be a new character for each case. </span></div><div><span style="font-size:13px">> I am not sure that putting colons between each case is really necessary though.</span></div><div><span style="font-size:13px"><br></span></div><div>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><br></div><div>This is why I like colons (this won't make sense unless your email has rich text to show the colors): </div><div><br></div><div><div><div style="margin:0px;font-size:13px;line-height:normal;font-family:Arial;color:rgb(96,96,96)"><b><span style="white-space:pre-wrap">        </span>let val = color ? </b></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:Arial;color:rgb(96,96,96)"><b><span style="white-space:pre-wrap">                </span></b><span style="color:rgb(227,36,0)"><b>.Red !</b></span><b> <span style="white-space:pre-wrap">        </span>0xFF0000 : </b></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:Arial;color:rgb(96,96,96)"><b><span style="white-space:pre-wrap">                </span></b><span style="color:rgb(227,36,0)"><b>.Green !</b></span><b> <span style="white-space:pre-wrap">        </span>0x00FF00 : </b></div><p style="font-size:13px;margin:0px;line-height:normal;font-family:Arial">
</p><div style="margin:0px;font-size:13px;line-height:normal;font-family:Arial;color:rgb(96,96,96)"><b><span style="white-space:pre-wrap">                </span></b><span style="color:rgb(227,36,0)"><b>_ !</b></span><b> <span style="white-space:pre-wrap">                </span>0xFFFFFF</b></div></div></div><div><b><br></b></div><div>... no syntax here different from the existing except the addition " <span style="font-family:Arial;font-size:13px;color:rgb(227,36,0)"><b>.Red !</b></span><span style="font-size:13px;font-family:Arial"> </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><span style="font-size:13px"><br></span></div><div><div style="font-size:13px;margin:0px;line-height:normal;font-family:Arial">> 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">> but maybe there is a better name.<br></div></div><div><span style="font-size:13px"><br></span></div><div>Has anyone suggested "multiary expression" yet? Seems in keeping with "ternary"<br></div><div><span style="font-size:13px"><br></span></div><div><span style="font-size:13px"><br></span></div><div><span style="font-size:13px"><br></span></div><div><span style="font-size:13px"><br></span></div><div><span style="font-size:13px"><br></span></div><div><br></div></div>
</div></blockquote></div><br></div>
</div></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="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></blockquote></div><br></div>