<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="">IMO `if x? { }` is not a lot shorter than `if let x = x`.</div><div class=""><br class=""></div><div class="">The problem with `if let` is, you need to explicit specify { } and call the function inside it. It is good for being explicit, but sometimes you ended up with something like this:</div><div class=""><br class=""></div><div class="">```</div><div class="">/* code 1 */</div><div class="">if let x = x, let y = y {</div><div class="">&nbsp; &nbsp; / * code 2 */</div><div class="">&nbsp; &nbsp; let z = foo(x, y)</div><div class="">&nbsp; &nbsp; if let z = z {</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; bar(z)</div><div class="">&nbsp; &nbsp; }</div><div class="">&nbsp; &nbsp; / * code 3 */</div><div class="">}</div><div class="">/* code 4 */</div><div class="">```</div><div class=""><br class=""></div><div class="">I would like to use guard if possible, but guard will force you to leave the entire function.</div><div class=""><br class=""></div><div class="">```</div><div class="">/ * code 1 */</div><div class="">guard let x = x, y = y else { return }</div><div class="">/* code 2 */</div><div class="">/ * some code */</div><div class="">guard let z = foo(x, y) else { return }</div><div class="">bar(z)</div><div class="">/ * code 3 */ // note: code 3 and code 4 won’t execute if x, y, or z is nil!</div><div class="">/ * code 4 */&nbsp;</div><div class="">```</div><div class=""><br class=""></div><div class="">What I really want is some like this:</div><div class=""><br class=""></div><div class="">```</div><div class="">/ * code 1 */</div><div class="">let z = foo(x?, y?)</div><div class="">/ * code 2 */</div><div class="">bar(z?)</div><div class="">/ * code 3 */ // note: code 3 and code 4 will still execute even if z is nil!</div><div class="">/ * code 4 */</div><div class="">```</div><div class=""><br class=""></div><div class="">IMO, this is much easier to read.</div><div class=""><br class=""></div><div class="">Sincerely,</div><div class="">Justin</div><div class=""><br class=""></div><br class=""><div><blockquote type="cite" class=""><div class="">On Aug 15, 2016, at 7:05 PM, Haravikk &lt;<a href="mailto:swift-evolution@haravikk.me" class="">swift-evolution@haravikk.me</a>&gt; 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 15 Aug 2016, at 08:02, Justin Jia via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Hi!<br class=""><br class="">I don’t know if this has came up before. I tried to search though the mailing list but didn’t find any related threads.<br class=""><br class="">This is purely a syntactic thing (which I know it’s the lowest priority for Swift 4), but I think it’s an important one.<br class=""><br class="">Let’s say we have a struct with a function:<br class=""><br class="">```<br class="">struct Foo {<br class=""> &nbsp;&nbsp;&nbsp;func bar(x: Int)<br class="">}<br class="">```<br class=""><br class="">We can use optionals:<br class=""><br class="">```<br class="">let foo: Foo? = nil<br class="">let x = 1<br class="">foo!.bar(x: x) // Able to compile, but will cause runtime error<br class="">foo?.bar(x: x) // Able to compile, and won't cause runtime error<br class="">```<br class=""><br class="">However:<br class=""><br class="">```<br class="">let foo = Foo()<br class="">let x: Int? = nil<br class="">foo.bar(x: x!) // Able to compile, but will cause runtime error<br class="">foo.bar(x: x?) // Won't compile<br class="">```<br class=""><br class="">I propose that we should allow `foo.bar(x: x?)`, which should be equivalent to:<br class=""><br class="">```<br class="">if let x = x {<br class=""> &nbsp;foo.bar(x: x)<br class="">}<br class="">```<br class=""><br class="">What do you think?</div></div></blockquote><br class=""></div><div class="">I like the intent behind this, but personally I think it's not clear enough. For me, putting the statement in a conditional as you've shown is the better solution, as it's a lot clearer exactly what's going on. Putting a question mark on a variable makes it look like something specific to that variable, rather than preventing the entire statement from executing.</div><div class=""><br class=""></div><div class="">There may be some alternatives though, for example, what about a shorthand for the conditional like so:</div><div class=""><br class=""></div><div class=""><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>if let x? { foo.bar(x: x) }</font></div><div class=""><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>if x? { foo.bar(x: x) } // even shorter?</font></div><div class=""><br class=""></div><div class="">But in general, I think it's best to be explicit about the entire statement being optional, which the conditional does but a postfix on a variable doesn't to the same degree.</div></div></div></blockquote></div><br class=""></body></html>