Next Previous Up Top Contents Index

4 The Trace Facility

4.3 Example

The following example illustrates howtrace may be used as a debugging tool. Suppose that you have defined a functionf, and intend its first argument to be a non-negative number. You can trap calls tof where this is not true, providing an entry into the main debugger in these cases. It is then possible for you to investigate how the problem arose.

To do this, you specify a:break option forf usingtrace. If the form following this option evaluates to a non-nil value upon calling the function, then the debugger is entered. In order to inspect the first argument to the functionf, you have access to the variable*traced-arglist*. This variable is bound to a list of the arguments with which the function was called, so the first member of the list corresponds to the first argument off when tracingf.

CL-USER 12 > (defun f (a1 a2) (+ (sqrt a1) a2))
F

CL-USER 13 > (trace (f :break (< (car *traced-arglist*) 0)))
F

CL-USER 14 > (f 9.0 3)
0 F > (9.0 3)
0 F < (6.0)
6.0

CL-USER 15 > (f -16.0 3)
0 F > (-16.0 3)

Break on entry to F
  1 (continue) return from break.
  2 (abort) return to level 0.
  3 return to top loop level 0.
  4 Destroy process.

Type :c followed by a number to proceed


LispWorks User Guide - 14 Oct 1998

Next Previous Up Top Contents Index

Generated with Harlequin WebMaker