Nested functions, how do they work (stack related)

Antoon Pardon antoon.pardon at rece.vub.ac.be
Tue Dec 13 06:44:39 EST 2016


Op 13-12-16 om 08:13 schreef Veek M:
> 4. When you call a nested function (decorator), it generally returns a 
> wrapper function but I thought he was just returning a reference to a 
> function object but obviously since it can see it's environment, how is 
> the stack being setup?

Here you are no longer just talking about nested functions, you are talking
about closures. A stack is no longer sufficient for implementing closures.
The environment for the nested variables of the closure is often alloceted
on the heap.

-- 
Antoon Pardon.



More information about the Python-list mailing list