NextPrevUpTopContentsIndex

5.2.1 Evaluating forms on entry to and exit from a traced function

:before

Trace keyword

:before list of forms

If non- nil , the list of forms is evaluated on entry to the function being traced. The forms are evaluated and the results printed after the arguments to the function.

Here is an example of its use. *traced-arglist* is bound to the list of arguments given to the function being traced. In this example, it is used to accumulate a list of all the arguments to fac across all iterations.

  1. In the listener, initialize the variable args-in-reverse as follows:
  2. (setq args-in-reverse ())
  3. For the fac function used earlier, set the value of :before to the following list:
  4. ((push (car *traced-arglist*) args-in-reverse))
  5. In the listener, evaluate the following form:
(fac 3)

After evaluating this form, args-in-reverse has the value (1 2 3) , that is, it lists the arguments which fac was called with, in the reverse order they were called in.

:after

Trace keyword

:after list of forms

If non- nil , this option evaluates a list of forms upon return from the function to be traced. The forms are evaluated and the results printed after the results of a call to the function.

This option is used in exactly the same way as :before . For instance, using the example for :before as a basis, create a list called results-in-reverse , and set the value of :after so that (car *traced-results*) is pushed onto this list. After calling fac , results-in-reverse contains the results returned from fac , in the reverse order they were called in.

Note: *traced-arglist* is still bound as well.


LispWorks User Guide - 7 Jul 2004

NextPrevUpTopContentsIndex