[swift-evolution] ternary operator ?: suggestion

Félix Cloutier felixcca at yahoo.ca
Tue Dec 22 12:30:55 CST 2015


This is essentially the latest proposal that Paul offered.

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 <mailto: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 <mailto:swift-evolution at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-evolution <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/d9f7d1bc/attachment.html>


More information about the swift-evolution mailing list