<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="">I just want to throw this out in case it changes your opinion - while the book does say that, the Swift library defines both of these:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><font face="Menlo" class="">@warn_unused_result</font></div><font face="Menlo" class="">public func ??<T>(optional: T?, @autoclosure defaultValue: () throws -> T?) rethrows -> T?</font><font face="Menlo" class=""><br class=""></font><font face="Menlo" class="">@warn_unused_result<br class=""></font><font face="Menlo" class="">public func ??<T>(optional: T?, @autoclosure defaultValue: () throws -> T) rethrows -> T</font></blockquote><div class=""><br class=""></div>This has the side-effect that this is legal code already today:<div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><font face="Menlo" class="">var o: Int? = nil</font></blockquote><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><font face="Menlo" class="">o = o ?? nil</font></blockquote><div class=""><div class=""><br class=""></div><div class="">I agree ??= has a much smaller surface area of potential use cases though.</div><div class=""><br class=""></div><div class="">A lot of times I have a need for something like this is when I'm parsing data into an unstructured type that will then later be realized into a strong type further in the pipeline. </div><div class=""><br class=""></div><div class="">-David</div><div class=""><br class=""></div><div><blockquote type="cite" class=""><div class="">On Feb 13, 2016, at 11:52 PM, David Waite via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><ul style="box-sizing: border-box; padding: 0px 0px 0px 2em; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class=""><li style="box-sizing: border-box;" class="">What is your evaluation of the proposal?</li></ul></div></div></blockquote>-1, on the basis of use being a potential anti-pattern, and the spec focusing on the benefit of a terser syntax over possible uses.</div><div class=""><br class=""></div><div class="">If there are additional uses outside the proposal, this evaluation may change.</div><div class=""><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><ul style="box-sizing: border-box; padding: 0px 0px 0px 2em; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class=""><li style="box-sizing: border-box;" class="">Is the problem being addressed significant enough to warrant a change to Swift?</li></ul></div></div></blockquote>Not as described. </div><div class=""><br class=""></div><div class="">“??” is described as the nil coalescing operator. It is defined as the following function:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">public</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> ??<T>(optional: T?, <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">@autoclosure</span> defaultValue: () <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">throws</span> -> T) <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">rethrows</span> -> <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">T</span></div><div style="margin: 0px; line-height: normal;" class="">The purpose of the nil coalescing operator is defined as follows by the Swift Programming Language book</div><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">“The nil coalescing operator (a ?? b) unwraps an optional a if it contains a value, or returns a default value b if a is nil. The expression a is always of an optional type. The expression b must match the type that is stored inside a.”</div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">This operator has thus two core properties:</div><div style="margin: 0px; line-height: normal;" class="">1. it allows another mechanism to deal with nil values, by specifying an alternate value to use in the nil case</div><div style="margin: 0px; line-height: normal;" class="">2. as either the value or the alternate is non-nil, it casts off optionality</div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">This operator does not do the second. It allows you to apply a value in the nil case, but the resulting value is still an optional. As such, I fear the usefulness of the “??=“ operator is greatly diminished.</div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">Note also that unlike other operators with inout equivalents like addition, the type of the left-hand input and the output are not the same in “??” due to the missing safe casting off of optionality.</div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div></div></div><div class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><ul style="box-sizing: border-box; padding: 0px 0px 0px 2em; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class=""><li style="box-sizing: border-box;" class="">Does this proposal fit well with the feel and direction of Swift?</li></ul></div></div></blockquote>The example given by the proposal is as follows:</div><div class=""><br class=""></div><div class=""><pre style="box-sizing: border-box; overflow: auto; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; padding: 16px; background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-wrap: normal; word-break: normal; color: rgb(51, 51, 51);" class="">really<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>long<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>lvalue[expression] <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> really<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>long<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>lvalue[expression] <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">??</span> <span class="pl-s" style="box-sizing: border-box; color: rgb(24, 54, 145);"><span class="pl-pds" style="box-sizing: border-box;">"</span><span class="pl-pds" style="box-sizing: border-box;">"</span></span></pre><div class=""><br class=""></div><div class="">In this case, you are setting a default value of “” to an optional target within a long expression.</div><div class=""><br class=""></div><div class="">However, it is unclear why the original expression allowed nil, or why setting this value to “” is an improvement.</div><div class=""><br class=""></div><div class="">To counter, some existing usage:</div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(61, 29, 129);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span><span style="" class=""> userDefaults = </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">NSUserDefaults</span><span style="" class="">.</span>standardUserDefaults<span style="" class="">()</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(61, 29, 129);" class=""><span style="color: rgb(187, 44, 162);" class="">let</span> repeatCount = <span style="color: rgb(79, 129, 135);" class="">userDefaults</span>.valueForKey(<span style="color: rgb(209, 47, 27);" class="">"repeatCount"</span>) <span style="color: rgb(187, 44, 162);" class="">as</span>? <span style="color: rgb(112, 61, 170);" class="">Int</span> ?? <span style="color: rgb(39, 42, 216);" class="">4</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">for</span> attempt <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">in</span> <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0</span>..<<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">repeatCount</span> {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="" class=""> </span>// ...</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">The for loop only works because repeatCount is non-optional. Assigning the value back into the expression would mutate the original value, but would still require one to cast off the optionality of the value.</div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><ul style="box-sizing: border-box; padding: 0px 0px 0px 2em; margin-top: 0px; margin-bottom: 16px; background-color: rgb(255, 255, 255);" class=""><li style="box-sizing: border-box;" class="">If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?</li></ul></div></div></blockquote>As mentioned, Ruby has a similar behavior. Other than the “false” and “nil” literal values, everything evaluates as true. The || and && operators preserve the values of the lhs and rhs arguments.</div><div class=""><br class=""></div><div class="">1 && 2 # is 2</div><div class="">1 || 2 # is 1</div><div class="">nil || 2 # is 2</div><div class=""><br class=""></div><div class="">As such, ||= can be used for such a default assignment system.</div><div class=""><br class=""></div><div class="">However, ruby does not have optionality. All libraries must take into account the possibility of sending nil in for a value. As such, it is not influenced by the limitations of this proposal.</div><div class=""> <br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><ul style="box-sizing: border-box; padding: 0px 0px 0px 2em; margin-top: 0px; margin-bottom: 16px; background-color: rgb(255, 255, 255);" class=""><li style="color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; box-sizing: border-box;" class="">How much effort did you put into your review? A glance, a quick reading, or an in-depth study?</li></ul></div></div></blockquote>In-between a reading and a study.</div><div class=""><br class=""></div><div class="">-DW</div><br class=""></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=""></div></body></html>