Next: , Up: Function Tracing   [Contents][Index]


3.10.1 Encapsulation Functions

The encapsulation functions provide a mechanism for intercepting the arguments and results of a function. ext:encapsulate changes the function definition of a symbol, and saves it so that it can be restored later. The new definition normally calls the original definition. The Common Lisp fdefinition function always returns the original definition, stripping off any encapsulation.

The original definition of the symbol can be restored at any time by the ext:unencapsulate function. ext:encapsulate and ext:unencapsulate allow a symbol to be multiply encapsulated in such a way that different encapsulations can be completely transparent to each other.

Each encapsulation has a type which may be an arbitrary lisp object. If a symbol has several encapsulations of different types, then any one of them can be removed without affecting more recent ones. A symbol may have more than one encapsulation of the same type, but only the most recent one can be undone.

Function: extensions:encapsulate symbol type body

Saves the current definition of symbol, and replaces it with a function which returns the result of evaluating the form, body. Type is an arbitrary lisp object which is the type of encapsulation.

When the new function is called, the following variables are bound for the evaluation of body:

extensions:argument-list

A list of the arguments to the function.

extensions:basic-definition

The unencapsulated definition of the function.

The unencapsulated definition may be called with the original arguments by including the form

    (apply extensions:basic-definition extensions:argument-list)
  

encapsulate always returns symbol.

Function: extensions:unencapsulate symbol type

Undoes symbol’s most recent encapsulation of type type. Type is compared with eq. Encapsulations of other types are left in place.

Function: extensions:encapsulated-p symbol type

Returns t if symbol has an encapsulation of type type. Returns nil otherwise. type is compared with eq.


Next: Tracing Examples, Up: Function Tracing   [Contents][Index]