[swift-evolution] ternary operator ?: suggestion
possen at gmail.com
Wed Dec 16 20:11:06 CST 2015
So maybe just eliminating the commas is enough, if possible I would like to avoid using parenthesis. I am not sure the rules, could do something like this
if possible would prefer not adding parens if possible (this is cleaner than the original proposal):
let a = sel ->> .Red: 1 .Green: 2 .Blue: 3
if it is necessary then something like this:
let a = (sel ->> .Red: 1, .Green: 2, .Blue: 3)
let a = (sel ->> .Red: 1 .Green: 2 .Blue: 3)
let a = sel ->(.Red: 1, .Green: 2, .Blue: 3)
So essentially it is a multiplexer.
> On Dec 16, 2015, at 4:36 PM, Paul Ossenbruggen <possen at gmail.com> wrote:
> Hi Chris,
> So, just trying to understand if you think this is a good direction to continue with or you think it is inherently flawed.
> Can you give me an example of a function argument list or array separator that we would have a problem? I will see if I can address it.
> Thanks for the feedback!
> - Paul
>> On Dec 16, 2015, at 3:14 PM, Chris Lattner <clattner at apple.com <mailto:clattner at apple.com>> wrote:
>> On Dec 16, 2015, at 2:56 PM, Paul Ossenbruggen via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>> I believe it also addresses the issues that Chris mentioned.
>>> to select from a boolean, a or b:
>>> let a = sel ->> true, false
>>> to select from an enum values as in a switch:
>>> let a = sel ->> .Red: 1, .Green: 2, .Blue: 3
>>> let b = sel ->> .Red: 1, .Green: 2, .Blue: 3, default: 4
>>> let c = sel ->> case .Red: 1, case .Green: 2, case .Blue: 3, default: 4
>>> let d = sel ->> .Red: 1, (sel ->> .Sun: .Yellow, .Moon: .White, .Stars: .Twinkle), .Green: 2, .Blue: 3, default: 4
>>> let e = sel ->> cases: .Red: 1, case .Green: 2, case .Blue: 3, default: 4
>>> • May be a slight improvement in readability. Operators have to be looked up if you are not familiar with them.
>>> • New concept that will have to be learned and not present in most C like languages so needs to be learned.
>> This specific proposal has another problem. Since you’re using “,” you’ve introduced grammar problems. For example, you wouldn’t be able to use this operator in a function argument list or array literal, because the , would be parsed as part of the argument list separator.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution