Explicit capture clauses
14 points by emschwartz
14 points by emschwartz
IMHO capturing places (instead of values) looks strange, even more so with the "rewrite" syntax: move(a.b.c = a.b.c.clone()) || .... You can use a.b.c but a.b.d becomes an error.
I'd only allow capturing values, but then it becomes slightly shorter version of a bunch of let bindings before a move || .... I guess they want a more concise syntax than that?
My other comment would be that there's no end to adding shorthands for common patterns, at some point you have to stop or your language will be getting more and more complex with every release (with new syntax, rules, exceptions to the rules, ...). Personally I'm not sure that we need shorthands here. Just making captures explicit should be good enough IMHO.
(In the past I used a macro to make captures explicit, but I can't remember the name now. IIRC it was commonly used with the GTK bindings.)
The macro is glib::clone!. It does a lot of stuff related to glib's object system, but in its simplest form it's a shorter form of
foo({
    let x = x.clone();
    move || {
        x
    }
})
I think the first form presented in the post (where you just define the "places" that are captured, without being able to perform operations like clone or ref) would be useful, but I'm really not sure about the rest of the proposals. Defining fresh variables is a bit overkill.
Niko slow down! Take a rest! It’s too many posts!