26 okt. 2016 kl. 21:23 skrev Chris Angelico rosuav@gmail.com:
On Thu, Oct 27, 2016 at 6:08 AM, Martin Karlgren marty@roxen.com wrote: A possible workaround is to cut the reference to the “foo” frame:
function f = lambda(string var1, string var2) { return lambda(string arg) { write("%O, %O, %O\n”, var1, var2, arg); }; }(var1, var2);
However, this is pretty verbose.
More significantly, this is *early binding* semantics. It captures the current values of var1 and var2, and won't notice any other changes.
Yep – don't know about other people but I don't think I've ever really wanted "late binding", so I think that's a good thing.
Also, all variables in the frame referenced by the lambda will be kept around, even if just a single one is actually used in the lambda.
This, however, could be changed - it's a simple question of optimization, so it comes down to "is it worth it". There's no semantic change there, AFAIK.
Correct, but I'm not sure if that theoretically simple optimization is feasible in practice.
/Marty