[swift-evolution] ternary operator ?: suggestion

Thorsten Seitz tseitz42 at icloud.com
Tue Dec 22 14:00:03 CST 2015


> Am 22.12.2015 um 19:30 schrieb Félix Cloutier <felixcca at yahoo.ca>:
> This is essentially the latest proposal that Paul offered.

The most similar proposal in his last mail seemed to be the following:

>> let b = switch(colorEnum then .Red: 0xFF0000, .Green: 0x00FF00, .Blue: 0x00000FF, default: 0xFFFFFF) 

This is quite different from the normal switch-syntax: parentheses instead of braces, "then" instead of "case" and only used once at the beginning while cases are separated by commas.

Apologies if I overlooked something.

-Thorsten

> Félix
> 
>> Le 22 déc. 2015 à 13:11:37, Thorsten Seitz <tseitz42 at icloud.com> a écrit :
>> 
>> I still don't understand why we are not simply writing
>> 
>> let i = switch color {
>>         case .Red: 0xFF0000
>>         case .Green: 0x00FF00
>>         case .Blue: 0x00000FF
>>     }
>> 
>> No additional keywords, no wondering why different keywords and different syntax is used for something so similar. And not really longer than the alternative proposals (I do not count swapping "case" with "?" to be a gain, especially not if it requires to add a comma after each case).
>> 
>> -Thorsten 
>> 
>> 
>>> Am 22.12.2015 um 15:31 schrieb Charles Constant via swift-evolution <swift-evolution at swift.org>:
>>> 
>>> Just goofing on this a little. What if we called it a "which" statement, instead of a "switch" statement? It's a bit cutesy, but not too verbose, and it makes sense if you read it aloud.
>>> 
>>> let i = which color {
>>> 	? .Red: 0xFF0000, 
>>> 	? .Green: 0x00FF00, 
>>> 	? .Blue: 0x00000FF
>>> }
>>> 
>>> let i = which boo {
>>> 	? true: 1, 
>>> 	? false: 0, 
>>> 	? nil: -1
>>> }
>>> 
>>> 
>>> _______________________________________________
>>> swift-evolution mailing list
>>> swift-evolution at swift.org
>>> https://lists.swift.org/mailman/listinfo/swift-evolution
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151222/e4fe1323/attachment.html>


More information about the swift-evolution mailing list