<div dir="ltr">Replies inline:<br><div class="gmail_extra"><br><div class="gmail_quote">On Sat, May 7, 2016 at 12:37 PM, Dave Abrahams 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:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span><br>
on Fri May 06 2016, Andrew Bennett <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br>
<br>
> Hi Dave,<br>
><br>
> Sorry, Dave, sending a second time as I forgot to Reply-All.<br>
><br>
> I agree, this proposal doesn't allow multiple closures where only one of them<br>
> should be run, and it should only be run once. I personally don't think lacking<br>
> that functionality is worth blocking this proposal for, another proposal can be<br>
> built on top of this if it is desired.<br>
><br>
> These cases can also be handled by a more meaningful if/switch statement, using<br>
> @noescape(once), for example:<br>
> let x: Int<br>
> functionThatCallsAClosure(someTest()) { x = $0 ? 1 : 2 }<br>
<br>
</span>Why is this better than<br>
<br>
let x = functionThatCallsAClosure(someTest()) { $0 ? 1 : 2 }<br>
<br>
?<br>
<br></blockquote><div><br></div><div>I'm not saying it's better, neither is the proposal. I do think both are better than this though:</div><div><br></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><span style="color:rgb(80,0,80)"><font face="monospace, monospace"> functionThatActsLikeIf( someTest(), then: { x = 1 }, else: { x = 2} )</font></span></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>My opinion is that cases where <i>the proposal</i> are limited by multiple closures seem to be cases where you would be better off with a single closure and more explicit control-flow. I'd be interested if there are other cases, but it currently seems like a straw-man argument to me.</div><div><br></div><div>--</div><div><br></div><div>It may be useful if Swift allowed things like this:</div><div><br></div><div><font face="monospace, monospace">let x = switch { ... }</font></div><div><font face="monospace, monospace">let x = if { ... } else { ... }</font></div><div><font face="monospace, monospace">etc.</font></div><div> <br></div><div>I think that's a much larger change/discussion, with no clear victor.</div><div><br></div><div>However until Swift has that support it's necessary to consider separated<span style="font-size:13px"> initialization and declaration. Likewise until all Swift is pure functional.</span></div><div><span style="font-size:13px"><br></span></div><div>Even if this proposal didn't let you assign to let statements outside the closure it still has value:</div><div><ul><li>It lets the type system reduce programmer error</li><li>It allows protocol declarations to have a more explicit requirement</li><li>The user can guarantee that their code, and its side-effects, will be executed</li></ul><div><br></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">
IMO separating initialization from declaration is *very* rarely needed<br>
and very much better avoided altogether, because it leads to code that's<br>
less clear. Just because we *can* do this doesn't mean we should.<br>
<div><div><br>
> On Sat, May 7, 2016 at 6:24 AM, Dave Abrahams via swift-evolution<br>
> <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br>
><br>
> on Tue May 03 2016, Chris Lattner<br>
> <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br>
><br>
> > Hello Swift community,<br>
> ><br>
> > The review of "SE-0073: Marking closures as executing exactly once"<br>
> > begins now and runs through May 9. The proposal is available here:<br>
> ><br>
> ><br>
> <a href="https://github.com/apple/swift-evolution/blob/master/proposals/0073-noescape-once.md" rel="noreferrer" target="_blank">https://github.com/apple/swift-evolution/blob/master/proposals/0073-noescape-once.md</a><br>
><br>
> ><br>
> > Reviews are an important part of the Swift evolution process. All reviews<br>
> should be sent to the swift-evolution mailing list at<br>
> ><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>
> ><br>
> > or, if you would like to keep your feedback private, directly to the<br>
> review manager.<br>
> ><br>
> > What goes into a review?<br>
> ><br>
> > The goal of the review process is to improve the proposal under review<br>
> > through constructive criticism and contribute to the direction of<br>
> > Swift. When writing your review, here are some questions you might<br>
> > want to answer in your review:<br>
> ><br>
> > * What is your evaluation of the proposal?<br>
><br>
> I think it's of questionable importance and doesn't generalize well.<br>
> For example, you can't use this to construct something like<br>
><br>
> var x: Int<br>
> functionThatActsLikeIf( someTest(), then: { x = 1 }, else: { x = 2} )<br>
><br>
> If you need to initialize something in an outer scope with something<br>
> computed by a closure, it's much better to arrange something like this:<br>
><br>
> var x = functionThatActsLikeIf( someTest(), then: { 1 }, else: { 2 } )<br>
><br>
> --<br>
> Dave<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>
><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>
<br>
--<br>
Dave<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>
</div></div></blockquote></div><br></div></div>