NextPrevUpTopContentsIndex

5.1 Simple tracing

This section shows you how to perform simple traces.

  1. Type this definition of the factorial function fac into the listener:
  2. (defun fac (n)
     (if (= n 1) 1
       (* n (fac (- n 1)))))
  3. Now trace the function by typing the following into the listener.
  4. (trace fac)
  5. Call the function fac as follows:
(fac 3)

The following trace output appears in the listener.

0 FAC > (3)
  1 FAC > (2)
    2 FAC > (1)
    2 FAC < (1)
  1 FAC < (2)
0 FAC < (6)

Upon entry to each traced function call, trace prints the following information:

Each call is indented according to the level of tracing for the call.

Upon exit from each call, the same information is produced: The > symbol denotes entry to a function, and the < symbol denotes exit from it.

Output produced in this way is always sent to a special stream, *trace-output* , which is either associated with the listener, or with background output. You can give other expressions to be sent to this stream, in addition to the arguments and results of a function.

Calling trace with no arguments produces a list of all the functions currently being traced. In order to cease tracing a function the macro untrace should be called with commands. All tracing can be removed by calling untrace with no arguments.

CL-USER 5 > (untrace fac)
NIL
CL-USER 6 > (fac 4)
24
 
CL-USER 7 > 

LispWorks User Guide - 8 Apr 2005

NextPrevUpTopContentsIndex