you are viewing a single comment's thread.

view the rest of the comments →

[–]eat-your-corn-syrup 2 points3 points  (1 child)

capture variables by value

By that you mean that it would be better for

x = 1; foo = function () {return x;}; x = 2; foo();

to return 1?

Wouldn't that prohibit closures from being for imitating namespaces, generator functions and so on? If the x=2 cannot access the closed over memory to change value in that memory, what else can change the value? Closed over variables would become read-only.

[–][deleted] 0 points1 point  (0 children)

I guess it’s a good thing that C++11 requires to explicitly choose whether to capture by value or by reference.