3 ms·
I'm not sure why you think there is a problem to be solved. When you execute some code you bind an environment to that code. (This binding step is necessary i
by btilly 17y ago
I'm not sure why you think there is a problem to be solved.
When you execute some code you bind an environment to that code. (This binding step is necessary if you want recursion to work.) In the case of a closure you just leave the environment bound to the function that returns. It is irrelevant how data got into the environment - as long as it is there and remains bound to that scope, the closure will work.
To be able to do this the environment needs to exist on the heap. However when you add the concurrency semantics that Go has, allocating things on the heap makes a ton of sense in general.