<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="">Oops, I had an example and decided to delete it.<div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Feb 15, 2016, at 8:52 PM, Paul Ossenbruggen <<a href="mailto:possen@gmail.com" class="">possen@gmail.com</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=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Feb 15, 2016, at 9:45 AM, Chris Lattner <<a href="mailto:clattner@apple.com" class="">clattner@apple.com</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="">On Feb 15, 2016, at 12:49 AM, Paul Ossenbruggen via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br 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=""><div class=""><div class=""><div class=""><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="color: rgb(79, 129, 135); font-family: Menlo; margin: 0px; line-height: normal;" class=""><br class=""></div><div class=""><span 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: inherit;" class="">The ? operator is unwrapped and the appendContentsOf method is only executed if the value is non-nil. </span><font color="#333333" face="Helvetica Neue, Helvetica, Segoe UI, Arial, freesans, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol" size="3" class=""><span style="background-color: rgb(255, 255, 255);" class="">However you can not do the following, which seems natural:</span></font></div><div class=""><font color="#333333" face="Helvetica Neue, Helvetica, Segoe UI, Arial, freesans, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol" size="3" class=""><br class=""></font></div></div></div></div></div></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><div class=""><div class=""><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><div class=""><span style="font-family: Menlo;" class="">a? + b</span></div></div></div></div></div></div></blockquote></div></div></blockquote><div class=""><br class=""></div><div class="">FWIW, "a?” is the degenerate form of the optional chaining operation, which tests A, conditionally extracts its value, then re-wraps it back up without performing any other operations on it. It is equivalent to “a?.identity()”. The compiler rejects it because it is confusing/surprising for people, not because it is undefined.</div></div></div></div></blockquote><div class=""><br class=""></div><div class="">Thanks for explaining that, that it is doing an identity and that is not undefined. I certainly missed that. . </div><div class=""><br class=""></div><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div class=""><br class=""></div><div class="">I would be very concerned with defining this operation to mean something else, because that introduces inconsistency and a completely different kind of surprise to the language.</div></div></div></div></blockquote><div class=""><br class=""></div><div class=""><br class=""></div><div class="">I am sorry, I am not getting why this is meaning something else, confusing or inconsistent, seems more consistent because you are returning an optional and that would not surprise me, it seems more surprising that you get an error. if it was already an optional and the expression as a whole results in a an optional, which is similar to what happens with optional chaining. With optional chaining, I expect it to return an optional as well, to me this seems very similar. If <b class="">a</b> is an optional, it would not be surprising for <b class="">a?</b> to return an optional. For example, </div></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><br class=""></div></div></div></blockquote><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=""><div class=""><div class=""><br class=""></div><blockquote type="cite" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><div class=""><div class=""><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><div class=""><div class=""><br class=""></div></div></div></div></div></div></div></blockquote><div class=""><div class=""><div class=""><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><div class=""><font color="#333333" face="Helvetica Neue, Helvetica, Segoe UI, Arial, freesans, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol" size="3" class="">To address this, the nil-coalescing operator would allow $$, where $$ is the unwrapped unnamed result of the expression when non nil: </font></div></div></div></div></div></div></div></blockquote><br class=""></div><div class="">Just to point one thing out, ?? is an operator in the stdlib. Doing something like this would require baking it into the compiler.</div><div class=""><br class=""></div></div></div></blockquote><div class=""><br class=""></div><div class="">I guess if auto closure could take a parameter you could do something like this:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(187, 44, 162);" class="">@warn_unused_result</div><div style="margin: 0px; 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: (result : T) <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; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span> optional != <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">nil</span> ? optional! : <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">try</span> defaultValue(result: optional!)</div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class="">}</div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div class="">I am not an expert on this though. I would acknowledge that to the later examples with multiple statements may be harder to do. </div></div><div class=""><br class=""></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=""><div class=""><br class=""></div><div class="">IMO, the problem you’re addressing is already adequately solved by guard.</div><div class=""><br class=""></div><div class="">-Chris</div><br class=""></div></div></blockquote></div><br class=""></div></div></blockquote></div><br class=""></div></body></html>