How would always behave if the function has an early return? Like so:<br><br>func testAlways(x: Int) {<br> print("non-deferred call")<br> return<br> let a = 3<br> always {<br> print("deferred call: \(a)")<br> }<br> }<br><div class="gmail_quote"><div dir="ltr">On Sat, Jan 2, 2016 at 9:56 AM Tim Hawkins via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">Again my 2 cents</p>
<p dir="ltr">Other languages use "deffer", and have very simular semantics, there is no benifit gained from being different, and it makes peoples task of transfering from other systems easier. </p>
<p dir="ltr">The percieved "simplicity" of the alternative semanatics and naming is subjective. What is there works just fine and achives the result it was designed to do. Why do we need to change it? </p>
<div class="gmail_quote">On Jan 3, 2016 1:47 AM, "Maury Markowitz via swift-evolution" <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
> On Jan 2, 2016, at 11:48 AM, Sebastian Mecklenburg via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br>
><br>
> I don’t think it’s confusing, I read ‘defer’ a ‘do it later’ and that’s just what it does. And the deferred calls are not always necessary so they can’t always be placed at the end.<br>
<br>
Can you be more specific about "deferred calls are not always necessary"? Do you mean that you could, for instance, place an if in front of the defer? If so one could do the same with always, of course. I'll use your example, slightly expanded, to illustrate<br>
<br>
> func testDefer(x: Int) {<br>
> defer {print("deferred call1")}<br>
> if x > 1 { defer {print("deferred call2")} }<br>
print("non-deferred call")<br>
> }<br>
<br>
I would rewrite this as:<br>
<br>
func testAlways(x: Int) {<br>
print("non-deferred call")<br>
always {<br>
print("deferred call1")<br>
if x > 1 print("deferred call2")<br>
}<br>
}<br>
<br>
Which is 100% equivalent to your example, but works precisely as you would expect without needing to "be aware" of any "logical consequence"s. The code runs exactly as it appears.<br>
<br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=EmLgVGNgdilXys3cXWyAWvOFC2-2FejnHkMVv8PyEdfbrX-2BICpAak9LCWyrjZv29rUW-2BwM1tZQ2YzLTQQs4Ka3qLVgPxPfCNDvqZUdORfKy7sxKsCpZvdzvu1H6H2h3EJQmzbwW00IpUtUOs85KiWqdQLhgHMyQia-2F4XkuDsght3kUpwKMqBy5BaUe2fcdnJffMRZzjcxcA3RqMdqr-2FNrk2s1b55DqRkMS0AJq6lv8M4Y-3D" alt="" width="1" height="1" border="0" style="min-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">
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div><div dir="ltr">-- <br></div>Javier Soto