Capture Clauses as Effects

11 points by aiono


lilyball

Regarding proposed syntax looking like

bar(with own(foo.a, foo.b, foo.c) || {
    baz(foo.a, foo.b, foo.c);
});

How does this work here, what is foo inside of the closure? Does this syntax make it so foo itself is meaningless in the closure and only the expressions foo.a, foo.b, and foo.c work?

aapoalas

Personally, I don't really see the benefit of Rust introducing explicit capture clauses. The language chose implicit capture and is (maybe? likely?) adding something like move(expr) to hoist code written inside the closure outside of it to make implicit capture of clones more ergonomic.

Adding an explicit capture clause on top of that is an unnecessary second way of doing the same thing - if you prefer it, you can hoist your captures to the top of the closure and use the move(expr) there. Yes, that's admittedly only a convention and there's nothing stopping you from accidentally also capturing something in the middle of the closure - by god if we get explicit capture clauses then they must stop implicit capture from happening in the same closure!

But I still do think this is an unnecessary duplication of features that we shouldn't introduce: you may prefer capture clauses, maybe I would as well, but that's not what we have today and we cannot walk back what we already have.