[swift-evolution] Proposal: An assignment operator := that ensures nil before assignment.

Stephen Celis stephen.celis at gmail.com
Sat Feb 27 09:11:37 CST 2016

> On Feb 27, 2016, at 9:34 AM, Amir Michail via swift-evolution <swift-evolution at swift.org> wrote:
> Consider the use of “!” in the following:
> var x: Int? = 5
> x! = 2 // “!” is used to ensure non-nil value before assignment
> The idea is to have a similar method for ensuring a nil value.
> So instead of writing:
> precondition( x == nil )
> x = 3
> You could write:
> x := 3

You could use an `inout` function to solve this now without adding surface area to the language and standard lib.

I've noticed, Amir, that people often ask you to flesh these ideas out more before submitting them to evolution. Would you please address these questions on this (and future) proposals? It might speed these discussions along.

- Why do you want this feature?

- Would you please provide a better, real-world example (perhaps code extracted from a real-world project you've worked on that would benefit) that demonstrates the benefits of your suggestion?

- Can you go into more detail on the the design of the proposal? How it may be implemented? Caveats? Alternatives considered?

Your emails to evolution are generally too short and not fleshed out enough to really evaluate.


More information about the swift-evolution mailing list