[swift-evolution] ternary operator ?: suggestion

Thorsten Seitz tseitz42 at icloud.com
Tue Dec 22 12:11:37 CST 2015


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/34f930b9/attachment.html>


More information about the swift-evolution mailing list