Next Previous Up Top Contents Index

4 The Trace Facility

4.1 Simple tracing

This section shows you how to perform simple traces.

1. Type this definition of the factorial functionfac into the listener:
(defun fac (n)
 (if (= n 1) 1
   (* n (fac (- n 1)))))

2. Now trace the function by typing the following into the listener.
(trace fac)

3. Call the functionfac 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.

Callingtrace with no arguments produces a list of all the functions currently being traced. In order to cease tracing a function the macrountrace should be called with commands. All tracing can be removed by callinguntrace with no arguments.

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

CL-USER 7 > 


LispWorks User Guide - 14 Oct 1998

Next Previous Up Top Contents Index

Generated with Harlequin WebMaker