Next: , Previous: Procedures, Up: Non-immediate Datatypes


A.2.5.4 Closures

[FIXME: this needs to be further subbed, but texinfo has no subsubsub]

A closure is a procedure object, generated as the value of a lambda expression in Scheme. The representation of a closure is straightforward — it contains a pointer to the code of the lambda expression from which it was created, and a pointer to the environment it closes over.

In Guile, each closure also has a property list, allowing the system to store information about the closure. I'm not sure what this is used for at the moment — the debugger, maybe?

— Macro: int SCM_CLOSUREP (SCM x)

Return non-zero iff x is a closure.

— Macro: SCM SCM_PROCPROPS (SCM x)

Return the property list of the closure x. The results are undefined if x is not a closure.

— Macro: void SCM_SETPROCPROPS (SCM x, SCM p)

Set the property list of the closure x to p. The results are undefined if x is not a closure.

— Macro: SCM SCM_CODE (SCM x)

Return the code of the closure x. The result is undefined if x is not a closure.

This function should probably only be used internally by the interpreter, since the representation of the code is intimately connected with the interpreter's implementation.

— Macro: SCM SCM_ENV (SCM x)

Return the environment enclosed by x. The result is undefined if x is not a closure.

This function should probably only be used internally by the interpreter, since the representation of the environment is intimately connected with the interpreter's implementation.