<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 &quot;|&quot;? To me, this doesn&#39;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 &quot;3 [Bitwise OR] 4&quot; or is the result &quot;3 [SEPARATOR] 4&quot;? 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">&lt;<a href="mailto:hello@alexpopov.ca" target="_blank">hello@alexpopov.ca</a>&gt;</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 &quot;range&quot; 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, &quot;Paul Ossenbruggen via swift-evolution&quot; <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</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&quot;ltr&quot;"><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)">&quot;</span><span style="line-height:normal;font-family:&#39;PingFang SC&#39;;color:rgb(209,47,27)">三</span><span style="color:rgb(209,47,27)">&quot;</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)">&quot;1&quot;</span>, <span style="color:rgb(209,47,27)">&quot;</span><span style="line-height:normal;font-family:&#39;Courier New&#39;;color:rgb(209,47,27)">١</span><span style="color:rgb(209,47,27)">&quot;</span>, <span style="color:rgb(209,47,27)">&quot;</span><span style="line-height:normal;font-family:&#39;PingFang SC&#39;;color:rgb(209,47,27)">一</span><span style="color:rgb(209,47,27)">&quot;</span>, <span style="color:rgb(209,47,27)">&quot;</span><span style="line-height:normal;font-family:Ayuthaya;color:rgb(209,47,27)">๑</span><span style="color:rgb(209,47,27)">&quot;</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)">&quot;2&quot;</span>, <span style="color:rgb(209,47,27)">&quot;</span><span style="line-height:normal;font-family:&#39;Courier New&#39;;color:rgb(209,47,27)">٢</span><span style="color:rgb(209,47,27)">&quot;</span>, <span style="color:rgb(209,47,27)">&quot;</span><span style="line-height:normal;font-family:&#39;PingFang SC&#39;;color:rgb(209,47,27)">二</span><span style="color:rgb(209,47,27)">&quot;</span>, <span style="color:rgb(209,47,27)">&quot;</span><span style="line-height:normal;font-family:Ayuthaya;color:rgb(209,47,27)">๒</span><span style="color:rgb(209,47,27)">&quot;</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)">&quot;3&quot;</span>, <span style="color:rgb(209,47,27)">&quot;</span><span style="line-height:normal;font-family:&#39;Courier New&#39;;color:rgb(209,47,27)">٣</span><span style="color:rgb(209,47,27)">&quot;</span>, <span style="color:rgb(209,47,27)">&quot;</span><span style="line-height:normal;font-family:&#39;PingFang SC&#39;;color:rgb(209,47,27)">三</span><span style="color:rgb(209,47,27)">&quot;</span>, <span style="color:rgb(209,47,27)">&quot;</span><span style="line-height:normal;font-family:Ayuthaya;color:rgb(209,47,27)">๓</span><span style="color:rgb(209,47,27)">&quot;</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)">&quot;4&quot;</span>, <span style="color:rgb(209,47,27)">&quot;</span><span style="line-height:normal;font-family:&#39;Courier New&#39;;color:rgb(209,47,27)">٤</span><span style="color:rgb(209,47,27)">&quot;</span>, <span style="color:rgb(209,47,27)">&quot;</span><span style="line-height:normal;font-family:&#39;PingFang SC&#39;;color:rgb(209,47,27)">四</span><span style="color:rgb(209,47,27)">&quot;</span>, <span style="color:rgb(209,47,27)">&quot;</span><span style="line-height:normal;font-family:Ayuthaya;color:rgb(209,47,27)">๔</span><span style="color:rgb(209,47,27)">&quot;</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>&quot;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>).&quot;<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>&quot;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>).&quot;<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 &quot;The integer value of <span style="line-height:normal;font-family:&#39;PingFang SC&#39;">三</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 &lt;<a href="mailto:charles@charlesism.com" target="_blank">charles@charlesism.com</a>&gt; 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">&gt; </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">&gt; separators for the ternary and so there needs to be a new character for each case.  </span></div><div><span style="font-size:13px">&gt; 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 &quot; let val = condition ? &quot; like the existing ternary. Let&#39;s say a proposal like that gets accepted... I really believe &quot;colons as separators&quot; is the best idea in the case. Otherwise, it gets pretty confusing.. we&#39;ll have the existing ternary where a colon does one thing, and our new &quot;extra ternary&quot; where it does something else. </div><div><br></div><div>This is why I like colons (this won&#39;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 &quot; <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>&quot;. As for the exclamation... Swift already uses an exclamation for a billion other things, which is unfortunate. But the same can be said of &quot;?&quot; and that&#39;s already used in a &quot;switch&quot; 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">&gt; 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">&gt; but maybe there is a better name.<br></div></div><div><span style="font-size:13px"><br></span></div><div>Has anyone suggested &quot;multiary expression&quot; yet? Seems in keeping with &quot;ternary&quot;<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>