<div dir="ltr"><div>I like this proposal, but I think I agree with Chris, the return value seems inconsistent.<br></div><div><br></div><div>I am +1 on rethrows.</div><div><br></div><div>Your proposed <span style="color:rgb(61,29,129);font-family:Menlo;font-size:11px">autoreleasepool</span> returns a (non discardable) value and/or performs a side-effect, depending on how it is being used. Also, most other standard library functions taking closures are methods that can be chained.<br></div><div><br></div><div>An interesting side-effect of this, not seen elsewhere:</div><br><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(61,29,129)"><span style="color:rgb(187,44,162)"> self</span><span style="color:rgb(0,0,0)">.</span><span style="color:rgb(79,129,135)">list</span><span style="color:rgb(0,0,0)">.</span>forEach<span style="color:rgb(0,0,0)"> { </span>print<span style="color:rgb(0,0,0)">($0) }</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="color:rgb(187,44,162)"> </span><span style="color:rgb(187,44,162)"> </span><span style="color:rgb(187,44,162)">self</span><span style="color:rgb(0,0,0)">.</span><span style="color:rgb(79,129,135)">list</span><span style="color:rgb(0,0,0)">.</span><span style="color:rgb(61,29,129)">dropLast</span><span style="color:rgb(0,0,0)">() </span>// warning: result unused</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="color:rgb(187,44,162)"> </span><span style="color:rgb(187,44,162)"> </span><span style="color:rgb(187,44,162)">self</span><span style="color:rgb(0,0,0)">.</span><span style="color:rgb(79,129,135)">list</span><span style="color:rgb(0,0,0)">.</span><span style="color:rgb(61,29,129)">removeLast</span><span style="color:rgb(0,0,0)">()</span><span style="color:rgb(0,0,0)"> </span>// no warning, the result is discardable<br></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><br></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="color:rgb(0,132,0)"> // all warnings, or no warnings</span><br></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)"> </span><span style="color:rgb(187,44,162)"> </span><span style="color:rgb(61,29,129)">autoreleasepool</span> { <span style="color:rgb(187,44,162)">self</span>.<span style="color:rgb(79,129,135)">list</span>.<span style="color:rgb(61,29,129)">forEach</span> { <span style="color:rgb(61,29,129)">print</span>($0) } }</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(49,89,93)"><span style="color:rgb(187,44,162)"> </span><span style="color:rgb(187,44,162)"> </span><span style="color:rgb(61,29,129)">autoreleasepool</span><span style="color:rgb(0,0,0)"> { </span><span style="color:rgb(187,44,162)">self</span><span style="color:rgb(0,0,0)">.</span><span style="color:rgb(79,129,135)">list</span><span style="color:rgb(0,0,0)">.</span><span style="color:rgb(61,29,129)">dropLast</span><span style="color:rgb(0,0,0)">() }</span></p><p style="margin:0px;font-size:11px;line-height:normal">
</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(49,89,93)"><span style="color:rgb(187,44,162)"> </span><span style="color:rgb(187,44,162)"> </span><span style="color:rgb(61,29,129)">autoreleasepool</span><span style="color:rgb(0,0,0)"> { </span><span style="color:rgb(187,44,162)">self</span><span style="color:rgb(0,0,0)">.</span><span style="color:rgb(79,129,135)">list</span><span style="color:rgb(0,0,0)">.</span><span style="color:rgb(61,29,129)">removeLast</span><span style="color:rgb(0,0,0)">() }</span></p></div><div><br></div><div>Currently the second call provides the appropriate warning. After this proposal either all or none of these calls will fire that warning (depending on the annotation). In other cases this is overcome with multiple functions; i.e. `forEach` versus `map`.</div><div><br></div><div><b>Solutions and Alternatives</b></div><div><b><br></b></div><div><b>Void version</b></div><div>You can provide a void version of the function, if you can get around the ambiguous function resolution, but that doesn't help with `<span style="font-family:Menlo;font-size:11px;color:rgb(61,29,129)">removeLast</span><span style="font-family:Menlo;font-size:11px;color:rgb(0,0,0)">()</span>` (the following linked proposal helps).</div><div><br></div><div>Shameless plug, I've got a proposal that would solve these issues:</div><div><a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160328/013559.html">https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160328/013559.html</a><br></div><div><br></div><div><b>Simplify current usage</b><br></div><div>A proposal like this one could improve the current usage:</div><div><a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160125/008167.html" target="_blank">https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160125/008167.html</a><br></div><div><br></div><div>It would allow us to do things like this (note the `<span style="color:rgb(187,44,162);font-family:Menlo;font-size:11px">let</span>`):</div><div><br></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> <span style="color:rgb(187,44,162)">let</span> x: <span style="color:rgb(112,61,170)">Int</span>, y: <span style="color:rgb(112,61,170)">Float</span>, z: <span style="color:rgb(112,61,170)">Double</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(61,29,129)"><span style="color:rgb(0,0,0)"> </span>autoreleasepool<span style="color:rgb(0,0,0)"> {</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> (x, y) = <span style="color:rgb(49,89,93)">calculateSomeStuff</span>()</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> z = <span style="color:rgb(49,89,93)">calculateMoreStuff</span>(x, y, <span style="color:rgb(39,42,216)">123</span>)</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">
</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> }</p></div><div><br></div><div>It would work with `@discardable`, and the function signature would be consistent with it having side-effects.</div><div><br></div><div><b>Discardable annotation</b><br></div><div>Maybe you can do this in the future (similar has been discussed, I forget the details):<b><br></b></div><div><b><br></b></div><div><span style="color:rgb(61,29,129);font-family:Menlo;font-size:11px"> autoreleasepool</span><span style="font-family:Menlo;font-size:11px;color:rgb(0,0,0)"> { () </span><span style="color:rgb(187,44,162);font-family:Menlo;font-size:11px">@discardable</span><span style="font-family:Menlo;font-size:11px;color:rgb(0,0,0)"> -> </span><span style="color:rgb(112,61,170);font-family:Menlo;font-size:11px">Int</span><span style="font-family:Menlo;font-size:11px;color:rgb(0,0,0)"> </span><span style="color:rgb(187,44,162);font-family:Menlo;font-size:11px">in</span><span style="font-family:Menlo;font-size:11px;color:rgb(0,0,0)"> ... }</span></div><div><br></div><div><b>New function, different name</b><br></div><div>If the current proposal did go ahead then I think the old function should stay around and your function should have a new name, because of the above reasons. Something like <font color="#3d1d81" face="Menlo"><span style="font-size:11px">autoreleasepoolvalue</span></font> although that's quite long.</div><div><br></div></div>