[swift-evolution] Lambda function syntax

Greg Parker gparker at apple.com
Tue Dec 22 18:03:09 CST 2015


> On Dec 22, 2015, at 3:45 PM, Alexander Regueiro via swift-evolution <swift-evolution at swift.org> wrote:
> 
> I’ve also explained the big problem with trailing closures already. And closures are really *not* control flow statements, so treating like them is just a fallacy and source of confusion.

Trailing closures allow you to write constructs that look and act as if they were control flow statements, which in practice is quite useful.

Closures do have control flow ramifications when reading code: the meaning of `return` inside a closure is different from its meaning in nearby code.

I personally favored `func` as the introducer for closures for precisely that reason. The presence of `func` would make it easier to recognize that there is something additional going on here, such as variable captures and `return` hijacking. Be warned that I lost that argument internally long ago.


> There are other arguments against it too, like it doesn’t generalise well (at all) to multiple closure arguments.

The argument that a feature does not generalize becomes much weaker when the special case is important enough. Single-closure argument lists like map and dispatch… and with… are common enough that special treatment is warranted.


-- 
Greg Parker     gparker at apple.com     Runtime Wrangler




More information about the swift-evolution mailing list