<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>+1 on ??= for consistency with ??<br><br>Sent from my iPad</div><div><br>On Dec 15, 2015, at 6:12 PM, Jordan Rose via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html charset=utf-8"><div class="">It's possible that <a href="https://github.com/apple/swift/blob/master/docs/TransparentAttr.rst" class="">@_transparent</a> is handled early enough in the compiler that we actually would get this behavior. I'm not sure, though.</div><div class=""><br class=""></div><div class="">+1 from me whether or not didSet is always called, though. "a = a ?? b" always calls didSet anyway.</div><div class=""><br class=""></div><div class="">Jordan</div><div class=""><br class=""></div><div class="">P.S. There's nothing particularly useful in the Radar, except that together with the dups there are three suggested spellings: "=?", "?=", and "??=". My vote is with Brent for "??=".</div><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 15, 2015, at 15:26 , James Campbell 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=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">:) Wasn't expecting it to be trivial. but yeah if it could somehow be short circuited so didSet, willSet isn't called when there is a value already. that would be awesome.<div class=""><br class=""></div><div class="">Could the willSet, didSet behaviour be tied to the = behaviour ? in your example above the operation ultimately cascades into a = operation. </div><div class=""><br class=""></div><div class="">Same with operations such as *= or /= ultimately it has to do a = operation to set the new calculated value.</div></div><div class="gmail_extra" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""><div class="gmail_quote">On Tue, Dec 15, 2015 at 11:23 PM, Jacob Bandes-Storch<span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:jtbandes@gmail.com" target="_blank" class="">jtbandes@gmail.com</a>></span><span class="Apple-converted-space"> </span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div dir="ltr" class="">I agree that would be nice. Just pointing out that it's nontrivial. If you implement this custom operator today, you get different behavior.<div class="gmail_extra"><span class="HOEnZb"><font color="#888888" class=""><br clear="all" class=""><div class=""><div class=""><div dir="ltr" class=""><div class="">Jacob<br class=""></div></div></div></div></font></span><div class=""><div class="h5"><br class=""><div class="gmail_quote">On Tue, Dec 15, 2015 at 3:21 PM, James Campbell<span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:james@supmenow.com" target="_blank" class="">james@supmenow.com</a>></span><span class="Apple-converted-space"> </span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div dir="ltr" class="">If it has a value already the nit wouldn't call anything as it technically hasn't been set. Only if it already has a value does it try and set something in which case the didSet is called :)</div><div class="gmail_extra"><br class=""><div class="gmail_quote"><div class=""><div class="">On Tue, Dec 15, 2015 at 11:16 PM, Jacob Bandes-Storch via swift-evolution<span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>></span><span class="Apple-converted-space"> </span>wrote:<br class=""></div></div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div class=""><div class=""><div dir="ltr" class="">One possible caveat is with custom setters.<div class=""><br class=""></div><div class="">If "a" already has a value, does "a ??= b" call the custom setter/willSet/didSet, or does it see the nil and short-circuit?</div><div class=""><br class=""></div><div class="">This can be implemented today:</div><div class=""><br class=""></div><div class=""> <span class="Apple-converted-space"> </span>func ??=(inout lhs: T?, @autoclosure rhs: () -> T?) { if lhs == nil { lhs = rhs() } }</div><div class=""><br class=""></div><div class="">However, the use of "inout" will always cause the didSets to be triggered at the call site, when just using if-statements instead wouldn't have done so.</div><div class="gmail_extra"><br clear="all" class=""><div class=""><div class=""><div dir="ltr" class=""><div class="">Jacob<br class=""></div></div></div></div><br class=""><div class="gmail_quote"><div class=""><div class="">On Tue, Dec 15, 2015 at 3:10 PM, Brent Royal-Gordon via swift-evolution<span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>></span><span class="Apple-converted-space"> </span>wrote:<br class=""></div></div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div class=""><div class=""><span class="">> I think that the existing syntax for “??” handles this need fairly well without requiring an additional assignment operator:<br class="">><br class="">> a = a ?? []<br class=""><br class=""></span>When the variable is `a`, sure. When it’s `scoreboardViewController.selectedScoreboard`, not so much.<br class=""><br class="">+1 from me, though I prefer the `??=` spelling to match the `??` operator more closely.<br class=""><span class=""><font color="#888888" class=""><br class="">--<br class="">Brent Royal-Gordon<br class="">Architechies<br class=""></font></span></div></div><div class=""><div class=""><br class=""><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" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></span></div></div></blockquote></div><br class=""></div></div></div></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=xV0JY-2FdZMnUMvSFtZnLiBPRTDDOSQf3-2FpH33HYOlBxHCmoqblRPu3QCZ5XRZruwnZ-2BGlsSXS7XHFBVRQTA-2B5NKBPecSkEMiEKqvTO5Loxd1XRhCgv-2BUMspC3PpyoJKT32QJ8AjHhSDZoG8JxbSxNRa0gU66lqARiwCJSzRUqw9vcSIIUcROAn9fZ1PyPletwh1fvNW7gUOt2JnzR-2FY7Cea7ouGlsomTcq5O1idJnkvA-3D" alt="" width="1" height="1" border="0" style="min-height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;" class=""><span class="Apple-converted-space"> </span><br class=""><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" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""><br class=""></span></blockquote></div><br class=""><br clear="all" class=""><span class=""><div class=""><br class=""></div>--<span class="Apple-converted-space"> </span><br class=""><div class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div dir="ltr" class=""><div class=""><span style="font-size: 16px; line-height: 19.2px;" class=""></span><span style="font-size: 12.8px;" class=""> Wizard</span><br class=""></div><div class=""><a href="mailto:james@supmenow.com" target="_blank" class="">james@supmenow.com</a></div><div class=""><a href="tel:%2B44%207523%20279%20698" value="+447523279698" target="_blank" class="">+44 7523 279 698</a></div></div></div></div></div></div></span></div></blockquote></div><br class=""></div></div></div></div></blockquote></div><br class=""><br clear="all" class=""><div class=""><br class=""></div>--<span class="Apple-converted-space"> </span><br class=""><div class="gmail_signature"><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div dir="ltr" class=""><div class=""><span style="font-size: 16px; line-height: 19.2px;" class=""></span><span style="font-size: 12.8px;" class=""> Wizard</span><br class=""></div><div class=""><a href="mailto:james@supmenow.com" target="_blank" class="">james@supmenow.com</a></div><div class="">+44 7523 279 698</div></div></div></div></div></div></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=ZEz4qHYnXhPr3bBPu-2FxP4tN3HfWKL-2FtJpqkQ0gkOVSABLoYxt-2BlrZpsND7lrKQYYppUVdpvXWp7hXpbAmPQ8h0pggR4LKcAbJRn3Fj1czpatT3DWRw2cYCXCkH6dxPT5JXzIDNynoUqXIEH7Vg2XIBWBpanrFtn-2FUz0bVivgbCWpNwczX6-2FViUfcv9haX6wdmSMJmqQeTDagYNmQsalAPRd9Dk02HRgtzuAQiKfsO6A-3D" alt="" width="1" height="1" border="0" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class=""><span class="Apple-converted-space"> </span>_______________________________________________</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">swift-evolution mailing list</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="mailto:swift-evolution@swift.org" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">swift-evolution@swift.org</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br class="">
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=eLFMrKDT8iBxZ-2Fbnk-2BZqvSchNN-2FvYXdceA0T7VxwkAd-2FxcRhRqa-2Bbx2OspR7y5iJnrB5LvW1D3r9LE6AkLenjo2NqfXrqYwez-2BxArWGCEhfscsQmD7WQA-2FIRGsig4By1x5B7vzMqkf0o-2FCtfljyQyo0RUb4LPqXdqDyyUQOX-2FeAGIHECpTLKgOwW2YIhOkanC3GrVeuqSB5SJYS5ErcsUnfJx-2Fdw5mitzp9NA4El3r0-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;">
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></body></html>