[swift-evolution] ternary operator ?: suggestion

Chris Lattner clattner at apple.com
Fri Dec 11 22:57:35 CST 2015

> On Dec 11, 2015, at 5:36 PM, Andrey Tarantsov via swift-evolution <swift-evolution at swift.org> wrote:
>> How about:
>> let v = if condition then “A" else “B"
> I don't think introducing a separate "then" keyword is a good idea, two subtly different kinds of IFs would be confusing.
> I guess you meant:
> let v = if condition { "A" } else { "B” }

I don’t really want to wade into this discussion, but if A and B are intended to be *expressions* instead of an arbitrary sequence of statements|decls|exprs, then a more consistent syntax would be:

	let v = if condition (A) else (b) 

The immediate problem with that is that juxtaposition of two expressions (condition, and A [with or without parens]) will lead to immediate syntactic ambiguity.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151211/0a258f49/attachment.html>

More information about the swift-evolution mailing list