If no uses are found (which I suspect will be the case), it becomes hard to also find evidence of harm other than in contrived scenarios. Perhaps contrived will be all we can find. Anyway, this is a bit off-topic for this thread...<br><div class="gmail_quote"><div dir="ltr">On Wed, Jan 25, 2017 at 11:24 AM John McCall <<a href="mailto:rjmccall@apple.com">rjmccall@apple.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg"><blockquote type="cite" class="gmail_msg"><div class="gmail_msg">On Jan 25, 2017, at 1:48 PM, Xiaodi Wu <<a href="mailto:xiaodi.wu@gmail.com" class="gmail_msg" target="_blank">xiaodi.wu@gmail.com</a>> wrote:</div><div class="gmail_msg">Given lack of evidence of harm, is it really important to make such a source-breaking change?<br class="gmail_msg"></div></blockquote><div class="gmail_msg"><br class="gmail_msg"></div></div></div><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg"><div class="gmail_msg">My first instinct is that, no, it's not important. However, we haven't actually *tried* to find any evidence of harm, so it's a bit conclusory. If someone wants to make an evidence-based argument that it's harmful and that almost nobody is using it (intentionally/correctly), the balance could swing the other way. That's for someone else to prove, though, since yes, at this point the bias has to be towards leaving things be.</div></div></div><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">John.</div></div></div><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"><blockquote type="cite" class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"><div class="gmail_quote gmail_msg"><div dir="ltr" class="gmail_msg">On Wed, Jan 25, 2017 at 12:45 John McCall via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a>> wrote:<br class="gmail_msg"></div><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg"><blockquote type="cite" class="gmail_msg"><div class="gmail_msg">On Jan 25, 2017, at 1:35 PM, Jacob Bandes-Storch <<a href="mailto:jtbandes@gmail.com" class="gmail_msg" target="_blank">jtbandes@gmail.com</a>> wrote:</div><br class="m_-6104765974600311638m_-30616251034729987Apple-interchange-newline gmail_msg"><div class="gmail_msg"><div dir="ltr" class="gmail_msg">Agreed, IMO it would be quite dangerous for "a ??= b" to mean anything other than "a = a ?? b".<div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">On another note, I don't see the value of "a? = b". I had never realized before that this works. Is this feature actually used in the wild? Should we consider removing it? (I could perhaps see some value if the assignment operator were overloadable, but it's not.)</div></div></div></blockquote><div class="gmail_msg"><br class="gmail_msg"></div></div></div><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg">The core semantics (that ? on an l-value still produces an l-value) fall out from the ability to call a mutating method with a?.foo(). Once you have that, you have to decide what it means to put such an l-value to the left of an assignment operator, and we decided to make it Just Work™. I agree that it is not a particularly useful operation in idiomatic Swift, especially with simple assignment (=), and we could consider just disallowing it.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">It also comes up with optional properties, I think, which is something we weren't always certain we were going to ban in native Swift (as opposed to imported ObjC code, where they're a fact of life).</div></div><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">John.</div></div><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"><blockquote type="cite" class="gmail_msg"><div class="gmail_msg"><div dir="ltr" class="gmail_msg"><div class="gmail_extra gmail_msg"><br clear="all" class="gmail_msg"><div class="gmail_msg"><div class="m_-6104765974600311638m_-30616251034729987m_3617066003682949734gmail_signature gmail_msg" data-smartmail="gmail_signature"><div dir="ltr" class="gmail_msg"><div class="gmail_msg">Jacob<br class="gmail_msg"></div></div></div></div>
<br class="gmail_msg"><div class="gmail_quote gmail_msg">On Wed, Jan 25, 2017 at 10:28 AM, John McCall <span dir="ltr" class="gmail_msg"><<a href="mailto:rjmccall@apple.com" class="gmail_msg" target="_blank">rjmccall@apple.com</a>></span> wrote:<br class="gmail_msg"><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg"><span class="gmail_msg"><blockquote type="cite" class="gmail_msg"><div class="gmail_msg">On Jan 25, 2017, at 12:47 PM, Jacob Bandes-Storch via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a>> wrote:</div><div class="gmail_msg">Really? My observation from a quick test is that "a? = b" assigns b to a if a already has a value, or does nothing if it's nil. This is sort of the opposite of what's being proposed, which is that "a ?= b" should assign to a only if it does NOT have a value.<br class="gmail_msg"></div></blockquote><div class="gmail_msg"><br class="gmail_msg"></div></span>Right. On the other hand, this does seem like a poor spelling for the operator, given the ease of confusion.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Also, I'm finding it hard to imagine a use for this where the equivalent ?? invocation wouldn't be *much* clearer. It just feels like you must be doing something backwards — "I've filled in a default value for this variable, now overwrite it if this other value exists". Wouldn't the reverse generally be better?</div><span class="m_-6104765974600311638m_-30616251034729987m_3617066003682949734HOEnZb gmail_msg"><font color="#888888" class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">John.</div></font></span><div class="gmail_msg"><div class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734h5"><div class="gmail_msg"><br class="gmail_msg"><blockquote type="cite" class="gmail_msg"><div class="gmail_msg"><div class="gmail_quote gmail_msg"><div dir="ltr" class="gmail_msg">On Wed, Jan 25, 2017 at 9:33 AM Joe Groff via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a>> wrote:<br class="gmail_msg"></div><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg">
> On Jan 25, 2017, at 8:40 AM, Nichi Shin via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg" target="_blank">swift-evolution@swift.org</a>> wrote:<br class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg">
><br class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg">
> I’d like to propose a new operator for optional assignment in Swift.<br class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg">
><br class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg">
> The idea is that by using this operator (e.g. by doing a ?= b), the optional on the right would be assigned to the variable on the left only when it has something to assign (i.e. when it's not nil).<br class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg">
<br class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg">
`a? = b` already does this. Maybe we need a fixit to make that more apparent, though.<br class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg">
<br class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg">
-Joe<br class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg">
<br class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg">
><br class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg">
> The implementation could be something as follows:<br class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg">
><br class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg">
> /// Optional Assignment Operator<br class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg">
> infix operator ?=: AssignmentPrecedence<br class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg">
><br class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg">
> func ?=<T>(left: inout T, right: T?) {<br class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg">
> if right != nil {<br class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg">
> left = right!<br class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg">
> }<br class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg">
> }<br class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg">
><br class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg">
> func ?=<T>(left: inout T?, right: T?) {<br class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg">
> if right != nil {<br class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg">
> left = right<br class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg">
> }<br class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg">
> }<br class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg">
><br class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg">
> I hope you will consider adding this on a future release of this great programming language.<br class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg">
><br class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg">
> Kind regards,<br class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg">
> N. S.<br class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg">
> _______________________________________________<br class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg">
> swift-evolution mailing list<br class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg">
> <a href="mailto:swift-evolution@swift.org" class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg" target="_blank">swift-evolution@swift.org</a><br class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg">
> <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg">
<br class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg">
_______________________________________________<br class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg">
swift-evolution mailing list<br class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg">
<a href="mailto:swift-evolution@swift.org" class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg" target="_blank">swift-evolution@swift.org</a><br class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="gmail_msg m_-6104765974600311638m_-30616251034729987m_3617066003682949734m_8108690658268912376gmail_msg">
</blockquote></div>
_______________________________________________<br class="gmail_msg">swift-evolution mailing list<br class="gmail_msg"><a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a><br class="gmail_msg"><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="gmail_msg"></div></blockquote></div><br class="gmail_msg"></div></div></div></blockquote></div><br class="gmail_msg"></div></div>
</div></blockquote></div><br class="gmail_msg"></div>_______________________________________________<br class="gmail_msg">
swift-evolution mailing list<br class="gmail_msg">
<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a><br class="gmail_msg">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="gmail_msg">
</blockquote></div>
</div></blockquote></div><br class="gmail_msg"></div></blockquote></div>