<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div><blockquote type="cite" class=""><div class="">On Jan 25, 2017, at 12:47 PM, Jacob Bandes-Storch via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><div class="">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=""></div></blockquote><div><br class=""></div>Right. &nbsp;On the other hand, this does seem like a poor spelling for the operator, given the ease of confusion.</div><div><br class=""></div><div>Also, I'm finding it hard to imagine a use for this where the equivalent ?? invocation wouldn't be *much* clearer. &nbsp;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". &nbsp;Wouldn't the reverse generally be better?</div><div><br class=""></div><div>John.</div><div><br class=""><blockquote type="cite" class=""><div class=""><div class="gmail_quote"><div dir="ltr" class="">On Wed, Jan 25, 2017 at 9:33 AM Joe Groff via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br class="gmail_msg">
&gt; On Jan 25, 2017, at 8:40 AM, Nichi Shin via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br class="gmail_msg">
&gt;<br class="gmail_msg">
&gt; I’d like to propose a new operator for optional assignment in Swift.<br class="gmail_msg">
&gt;<br class="gmail_msg">
&gt; 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">
<br class="gmail_msg">
`a? = b` already does this. Maybe we need a fixit to make that more apparent, though.<br class="gmail_msg">
<br class="gmail_msg">
-Joe<br class="gmail_msg">
<br class="gmail_msg">
&gt;<br class="gmail_msg">
&gt; The implementation could be something as follows:<br class="gmail_msg">
&gt;<br class="gmail_msg">
&gt; /// Optional Assignment Operator<br class="gmail_msg">
&gt; infix operator ?=: AssignmentPrecedence<br class="gmail_msg">
&gt;<br class="gmail_msg">
&gt; func ?=&lt;T&gt;(left: inout T, right: T?) {<br class="gmail_msg">
&gt;&nbsp; &nbsp; &nbsp;if right != nil {<br class="gmail_msg">
&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;left = right!<br class="gmail_msg">
&gt;&nbsp; &nbsp; &nbsp;}<br class="gmail_msg">
&gt; }<br class="gmail_msg">
&gt;<br class="gmail_msg">
&gt; func ?=&lt;T&gt;(left: inout T?, right: T?) {<br class="gmail_msg">
&gt;&nbsp; &nbsp; &nbsp;if right != nil {<br class="gmail_msg">
&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;left = right<br class="gmail_msg">
&gt;&nbsp; &nbsp; &nbsp;}<br class="gmail_msg">
&gt; }<br class="gmail_msg">
&gt;<br class="gmail_msg">
&gt; I hope you will consider adding this on a future release of this great programming language.<br class="gmail_msg">
&gt;<br class="gmail_msg">
&gt; Kind regards,<br class="gmail_msg">
&gt; N. S.<br class="gmail_msg">
&gt; _______________________________________________<br class="gmail_msg">
&gt; swift-evolution mailing list<br class="gmail_msg">
&gt; <a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a><br class="gmail_msg">
&gt; <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">
<br class="gmail_msg">
_______________________________________________<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>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>