The following example illustrates how trace may be used as a debugging tool. Suppose that you have defined a function f,
and intend its first argument to be a non-negative number. You can trap calls to f
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 for f
using trace. 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 function f
, 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 of f
when tracing f
.
CL-USER 1 > (defun f (a1 a2) (+ (sqrt a1) a2))
F
CL-USER 2 > (trace (f :break (< (car *traced-arglist*) 0)))
(F)
CL-USER 3 > (f 9.0 3)
0 F > ...
>> A1 : 9.0
>> A2 : 3
0 F < ...
<< VALUE-0 : 6.0
6.0
CL-USER 4 > (f -16.0 3)
0 F > ...
>> A1 : -16.0
>> A2 : 3
Break on entry to F with *TRACED-ARGLIST* (-16.0 3).
1 (continue) Return from break.
2 Continue with trace removed.
3 Continue traced with break removed.
4 Continue and break when this function returns.
5 (abort) Return to level 0.
6 Return to top loop level 0.
Type :b for backtrace or :c <option number> to proceed.
Type :bug-form "<subject>" for a bug report template or :? for other options.
CL-USER 5 : 1 >
LispWorks User Guide and Reference Manual - 13 Feb 2015