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

Taras Zakharko taras.zakharko at uzh.ch
Sat Feb 27 13:13:52 CST 2016

> On 27 Feb 2016, at 18:02, Amir Michail via swift-evolution <swift-evolution at swift.org> wrote:
> Here’s a use case. Suppose you are filling out a dictionary in some non-trivial way. However, it should be the case that the value for each key is computed and assigned only once. And so you would use the := operator to ensure this: dictionary[k] := value

No, you would define an extension method for the Dictionary that does exactly this.

The issue I have with your proposal is that it suggests to introduce a new privileged syntax (a very unfortunate one at that)  for doing a very niche operation.  If you need this construct: define it in your code. If you think it is generally useful: suggest it as an extension to the standard library. However, I at least see no reason why this should be a primary privileged operation in the language grammar itself. 

— Taras
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160227/480e6eeb/attachment.html>

More information about the swift-evolution mailing list