2 ms·
Sorry, why wouldn't closing over a variable by value count as a closure? In fact in many functional languages you can't tell the difference.
by gpderetta 4y ago
Sorry, why wouldn't closing over a variable by value count as a closure? In fact in many functional languages you can't tell the difference.
- int_19h 4y agoIn functional languages where you can't tell the difference, like ML or Haskell, values are bound directly to variables, so capturing the value is closing over the variable. But in C++, variables represent storage locations which contain values, so if you copy the value, you're not really closing over the variable (unless it's const). To look at it from another perspective, if a closure closes over the variable, then references to that variable inside the closure should behave the same as references to that variable outside of it. If you can change the variable value outside, and it's not reflected inside the closure, then it's not really the same variable inside and outside.