[plt-scheme] Closure Representation

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Fri May 18 18:55:02 EDT 2007

At Fri, 18 May 2007 13:59:22 -0400, "Marco Morazan" wrote:
> Can anyone point me to a document or web page that describes how closures
> are represented in PLT Scheme?

What level of detail are you looking for?

For the basic architecture, there's no document specific to PLT Scheme,
but the implementation is one of the typical points in the spectrum
described by textbooks. MzScheme's closures are essentially "flat": a
code pointer is packaged with the values (or boxes, in the case of
mutable variables) associated with its free variables. For module-level
bindings, though, there's an extra indirection: one reference in the
closure record to an array of module bindings (and the array is shared
for all closures in the same module).

If you want to know the actual byte layout for some reason, see
`Scheme_Closure' and `Scheme_Native_Closure' in
"src/mzscheme/src/schpriv.h". Beware that the `vals' array is not
actually an array of values; it can contain mutable-variable
indirections and a module-level array, as noted above.


Posted on the users mailing list.