[Python-ideas] A "local" pseudo-function

Greg Ewing greg.ewing at canterbury.ac.nz
Tue May 1 05:26:09 EDT 2018


Steven D'Aprano wrote:
> So what was the closure? If the surrounding function was still running, 
> there was no need to capture the running environment in a closure?

You seem to be interpreting the word "closure" a bit
differently from most people. It doesn't imply anything
about whether a surrounding function is still running or
not.

A closure is just a piece of code together with a runtime
environment. In typical Pascal implementations, a closure
is represented by a (code_address, frame_pointer) pair,
where the frame_pointer points to a chain of lexically
enclosing stack frames. The language rules make it possible
to manage the frames strictly stack-wise, which simplifies
the memory management, but that doesn't make the closure
any less of a closure.

Contrast this with Modula-2, where only top-level functions
can be passed as parameters. When you pass a function in
Modula-2, only the code address is passed, with no
environment pointer.

-- 
Greg


More information about the Python-ideas mailing list