<div dir="ltr">It has been mentioned before (more than once, perhaps, but not in its own thread I don't think, so good luck finding it). IIRC, one of the problems is that it's unclear what happens if your function takes multiple arguments. Does evaluation proceed from left to right? does it short-circuit? Put concretely:<div><br></div><div>```</div><div>func bar(_ x: Int) -> Int? { /* side effects */ }</div><div>func baz(_ y: Int) -> Int? { /* side effects */ }</div><div>func foo(_ z: Int, _ a: Int) -> Int { /* ... */ }</div><div><br></div><div>print(foo(bar(42)?, baz(42)?))</div><div>```</div><div><br></div><div>Does baz(42) get evaluated if bar returns nil? Does bar(42) get evaluated if baz returns nil?<br><div class="gmail_extra"><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Aug 15, 2016 at 2:02 AM, Justin Jia via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi!<br>
<br>
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>
<br>
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>
<br>
Let’s say we have a struct with a function:<br>
<br>
```<br>
struct Foo {<br>
func bar(x: Int)<br>
}<br>
```<br>
<br>
We can use optionals:<br>
<br>
```<br>
let foo: Foo? = nil<br>
let x = 1<br>
foo!.bar(x: x) // Able to compile, but will cause runtime error<br>
foo?.bar(x: x) // Able to compile, and won't cause runtime error<br>
```<br>
<br>
However:<br>
<br>
```<br>
let foo = Foo()<br>
let x: Int? = nil<br>
foo.bar(x: x!) // Able to compile, but will cause runtime error<br>
foo.bar(x: x?) // Won't compile<br>
```<br>
<br>
I propose that we should allow `foo.bar(x: x?)`, which should be equivalent to:<br>
<br>
```<br>
if let x = x {<br>
foo.bar(x: x)<br>
}<br>
```<br>
<br>
What do you think?<br>
<br>
Thanks,<br>
Justin<br>
<br>
______________________________<wbr>_________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br>
</blockquote></div><br></div></div></div>