<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 class="">The situation in which I found a little confusing that that was the same operator, was something like that:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""><div style="margin: 0px;" class=""><span style="color: rgb(187, 44, 162);" class="">func</span> someFunction() -> <span style="color: rgb(79, 129, 135);" class="">T</span> {</div><div style="margin: 0px; min-height: 13px;" class=""> <br class="webkit-block-placeholder"></div><div style="margin: 0px;" class=""> <span style="color: rgb(187, 44, 162);" class="">var</span> someValue: <span style="color: rgb(79, 129, 135);" class="">T</span></div><div style="margin: 0px; min-height: 13px;" class=""> <br class="webkit-block-placeholder"></div><div style="margin: 0px; color: rgb(0, 132, 0);" class=""><span style="color: rgb(0, 0, 0);" class=""> </span>/* some code */</div><div style="margin: 0px; min-height: 13px;" class=""> <br class="webkit-block-placeholder"></div><div style="margin: 0px;" class=""> <span style="color: rgb(187, 44, 162);" class="">var</span> value = someOptionalValue ?? someValue</div><div style="margin: 0px; min-height: 13px;" class=""> <br class="webkit-block-placeholder"></div><div style="margin: 0px; color: rgb(0, 132, 0);" class=""><span style="color: rgb(0, 0, 0);" class=""> </span>/* some code */</div><div style="margin: 0px; min-height: 13px;" class=""> <br class="webkit-block-placeholder"></div><div style="margin: 0px;" class=""> <span style="color: rgb(187, 44, 162);" class="">return</span> value</div><div style="margin: 0px;" class="">}</div><div style="margin: 0px;" class=""><br class=""></div></div></div><div class="">For some reasons, I had to consider a new case where someValue had to be an optional</div><div class=""><br class=""></div><div class=""><div class=""><div style="margin: 0px;" class=""><div style="font-family: Menlo; font-size: 11px; margin: 0px;" class=""><span style="color: rgb(187, 44, 162);" class="">func</span> someFunction() -> <span style="color: rgb(79, 129, 135);" class="">T</span> {</div><div style="font-family: Menlo; font-size: 11px; margin: 0px; min-height: 13px;" class=""> <br class="webkit-block-placeholder"></div><div style="font-family: Menlo; font-size: 11px; margin: 0px;" class=""> <span style="color: rgb(187, 44, 162);" class="">var</span> someValue: <span style="color: rgb(79, 129, 135);" class="">T?</span></div><div style="font-family: Menlo; font-size: 11px; margin: 0px; min-height: 13px;" class=""> <br class="webkit-block-placeholder"></div><div style="font-family: Menlo; font-size: 11px; margin: 0px; color: rgb(0, 132, 0);" class=""><span style="color: rgb(0, 0, 0);" class=""> </span>/* some code */</div><div style="font-family: Menlo; font-size: 11px; margin: 0px; min-height: 13px;" class=""> <br class="webkit-block-placeholder"></div><div style="font-family: Menlo; font-size: 11px; margin: 0px;" class=""> <span style="color: rgb(187, 44, 162);" class="">var</span> value = someOptionalValue ?? someValue</div><div style="font-family: Menlo; font-size: 11px; margin: 0px; min-height: 13px;" class=""> <br class="webkit-block-placeholder"></div><div style="font-family: Menlo; font-size: 11px; margin: 0px; color: rgb(0, 132, 0);" class=""><span style="color: rgb(0, 0, 0);" class=""> </span>/* some code */</div><div style="font-family: Menlo; font-size: 11px; margin: 0px; min-height: 13px;" class=""> <br class="webkit-block-placeholder"></div><div style="margin: 0px;" class=""><font face="Menlo" class=""><span style="font-size: 11px;" class=""> </span></font><span style="font-family: Menlo; font-size: 11px; color: rgb(187, 44, 162);" class="">return</span><font face="Menlo" class=""><span style="font-size: 11px;" class=""> value</span></font><span class="Apple-tab-span" style="font-family: Menlo; font-size: 11px; white-space: pre;">        </span><span style="font-family: Menlo; font-size: 11px; color: rgb(0, 132, 0);" class="">// </span><font color="#008400" face="Menlo" class=""><span style="font-size: 11px;" class="">error: value of optional type 'T?' not unwrapped; did you mean to use '!'</span></font><span style="font-family: Menlo; font-size: 11px; color: rgb(0, 132, 0);" class=""> </span></div><div style="font-family: Menlo; font-size: 11px; margin: 0px;" class="">}</div><div style="font-family: Menlo; font-size: 11px; margin: 0px;" class=""><br class=""></div></div></div><div class="">In my point of view, the error was not at the return line but rather at the declaration of <span style="font-family: Menlo; font-size: 11px;" class="">value</span>. The existence of two operators would have forced me in the first case to use <span style="font-family: Menlo; font-size: 11px;" class="">?!</span> to have <span style="font-family: Menlo; font-size: 11px;" class="">value</span> as a non optional, and would make the localisation of the error obvious.</div></div><div class=""><br class=""></div><div class="">The operator <span style="font-family: Menlo; font-size: 11px;" class="">?!</span> have to have a lower precedence to return the non optional value after that <span style="font-family: Menlo; font-size: 11px;" class="">??</span> returned the optional one.</div><div class="">Having two operators would not prevent programmers from chaining. The case:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">var</span> value = someArray ?? someFallback ?? secondaryFallback ?? []</div></div><div class=""><br class=""></div><div class="">would just be replaced by:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">var</span> value = someArray ?? someFallback ?? secondaryFallback ?! []</div></div><div class=""><br class=""></div><div class="">Same changes would occur everywhere value is non optional. With these changes, I don't see any situation where code would be broken.</div><div class=""><br class=""></div><div class="">--</div><div class="">Sébastien Blondiau</div><div class=""><br class=""></div><div><blockquote type="cite" class=""><div class="">Le 7 mars 2016 à 23:53, Ross O'Brien <<a href="mailto:narrativium+swift@gmail.com" class="">narrativium+swift@gmail.com</a>> a écrit :</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">During the review of the proposal for a '??=' operator, one of the given disadvantages was the confusion over the meaning of '??'. Since one of its two meanings is that it nil-coalesces a chained expression into a non-optional result, it might be misinterpreted that given the expression 'lhs ??= rhs' and a non-optional 'rhs', 'lhs' would no longer be optional. '??' is an overloaded operator; unloading one of its two responsibilities to a second operator would improve code clarity.<div class=""><br class=""></div><div class="">Radoslaw's example is simplistic because '[]' is unambiguously non-optional. So let's replace it:</div><div class=""><br class=""></div><div class=""><span style="font-size:13px" class="">var value = someArray ?? someFallback ?? secondaryFallback ?? tertiaryFallback</span><br class=""></div><div class=""><br class=""></div><div class="">Is 'value' optional or non-optional?</div><div class=""><br class=""></div><div class=""><span style="font-size:13px" class="">var value = someArray ?? someFallback ?? secondaryFallback ?! tertiaryFallback</span><br class=""></div><div class=""><br class=""></div><div class="">Now we can see immediately that 'value' is optional in the first case, and non-optional in the second. However, since '!' is associated with assertions, I agree that perhaps there's a better choice of operator for this meaning.</div><div class=""><br class=""></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Mon, Mar 7, 2016 at 10:26 PM, Radosław Pietruszewski <span dir="ltr" class=""><<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>></span> wrote:<br class=""><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=""><div class="">-1, never seen a real world situation where this would be confusing/problematic.</div><div class=""><br class=""></div><div class="">Having one operator is nice for chaining:</div><div class=""><br class=""></div><div class="">var value = someArray ?? someFallback ?? secondaryFallback ?? []</div><br class=""><div class="">
<div class="">— Radek</div>
</div>
<br class=""><div class=""><blockquote type="cite" class=""><div class=""><div class="h5"><div class="">On 07 Mar 2016, at 22:29, Sébastien Blondiau via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>> wrote:</div><br class=""></div></div><div class=""><div class=""><div class="h5"><div style="word-wrap:break-word" class=""><div class="">Currently, there is only one nil coalescing operator, which may return an optional value or not, depending on the second parameter. This variability can leads to unclear line of code:</div><div class=""><br class=""></div><div class=""><div style="margin:0px;font-size:11px;font-family:Menlo" class=""><div style="margin:0px" class=""><span style="color:rgb(187,44,162)" class="">var</span><span class=""> isItOptionalOrNot = </span><font color="#4f8187" class="">value</font><span class=""> ?? </span><font color="#4f8187" class="">otherValue</font></div><div style="color:rgb(79,129,135);margin:0px" class=""><br class=""></div></div><div class="">I think there should be two distinct operators:</div><div class=""><br class=""></div><div class=""><div style="margin:0px;font-size:11px;font-family:Menlo" class=""><div style="font-family:Helvetica;font-size:12px" class=""><div style="margin:0px;font-size:11px;font-family:Menlo" class=""><span style="color:rgb(187,44,162)" class="">var</span><span class=""> certainlyOptional = </span><font color="#4f8187" class="">value</font><span class=""> </span><span class="">?? </span><font color="#4f8187" class="">otherValue</font></div><div class=""><div style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(79,129,135)" class=""><span style="color:rgb(187,44,162)" class="">var</span><span class=""> </span><span class="">certainlyNotOptional</span><span class=""> = </span><font color="#4f8187" class="">value</font><span class=""> ?! </span><font color="#4f8187" class="">notOptionalValue</font></div></div><div class=""><br class=""></div></div></div></div><div class="">In my point of view, this differentiation brings more clarity about wether the result is an optional or not.</div></div><div class=""><br class=""></div><div class="">What's your opinion?</div><div class=""><br class=""></div><div class="">--</div><div class="">Sébastien Blondiau</div></div></div></div><span class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></span></div></blockquote></div><br class=""></div><br class="">_______________________________________________<br class="">
swift-evolution mailing list<br class="">
<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
<br class=""></blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></body></html>