[swift-evolution] Proposal: Replace ?? by an (optional) argument to ?

Austin Zheng austinzheng at gmail.com
Mon Jan 25 20:59:05 CST 2016

In addition to the conflict in meaning, the original proposal won't work as-is because only operators can start with a '?'. An 'ifNil' function taking an autoclosure argument would be expressible within the language grammar without requiring special-case exceptions.

That being said, my opinion is that changes that break existing code should come with commensurate benefit (as with the C for loop discussion). I don't think one exists, although if someone wants to make an argument in favor of it I would be happy to reconsider.

WRT to ?? not being well-known, given that the concept it deals with (non-optional fallback expression to an expression of optional type) is not really expressible in most mainstream languages, I would consider it okay.


> On Jan 25, 2016, at 6:52 PM, Rob Mayoff via swift-evolution <swift-evolution at swift.org> wrote:
> `x?(false)` already has a meaning. If `x` is of type `Optional<(Bool) -> ()>`, then `x?(false)` means “if x is None, do nothing; if x is Some(f), call f(false)”.
> I don't think the end is "the most important position", and I don't think the default value is necessarily "the least important part of the expression".
> I like the existing ?? operator more than this idea.
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

More information about the swift-evolution mailing list