A simple debugging macro
- From: "fairchild.anthony@xxxxxxxxx" <fairchild.anthony@xxxxxxxxx>
- Date: Thu, 29 Nov 2007 20:08:30 -0800 (PST)
Hello all,
I wrote this simple macro a while back and I've found it to be
extremely useful for old-fashioned trace style debugging. Maybe
others will find it useful as well. Thoughts or criticism are
welcome. Perhaps others have similar macros or other methods of doing
this that are better.
This is the macro:
(eval-when (:compile-toplevel :load-toplevel :execute)
(defvar *debug* t)
(defmacro print-vars (&rest vars)
"Prints variables listed in vars to *trace-output*. The first
argument can be a string which will be printed directly."
(when *debug*
`(progn (format *trace-output* "TRACE: ")
,(when (stringp (first vars))
`(format *trace-output* "~A " ,(pop vars)))
,@(loop for var in vars
collect `(format *trace-output* "~A=~S "
',var ,var))
(format *trace-output* "~%" )
(finish-output *trace-output*)))))
This is how you use it:
CL-USER 46 > (let ((a 10))
(print-vars "before fib loop" a)
(loop for n from 1 to a
for x = 1 then y
and y = 1 then (+ x y)
do (print-vars n x y))
(print-vars "after fib loop" (* a a)))
TRACE: before fib loop A=10
TRACE: N=1 X=1 Y=1
TRACE: N=2 X=1 Y=2
TRACE: N=3 X=2 Y=3
TRACE: N=4 X=3 Y=5
TRACE: N=5 X=5 Y=8
TRACE: N=6 X=8 Y=13
TRACE: N=7 X=13 Y=21
TRACE: N=8 X=21 Y=34
TRACE: N=9 X=34 Y=55
TRACE: N=10 X=55 Y=89
TRACE: after fib loop (* A A)=100
NIL
Regards,
Anthony
.
- Follow-Ups:
- Re: A simple debugging macro
- From: Ken Tilton
- Re: A simple debugging macro
- From: Rainer Joswig
- Re: A simple debugging macro
- Prev by Date: Re: The origins of CL conditions system
- Next by Date: Re: A simple debugging macro
- Previous by thread: Why doesn't (open ... :if-exists) support :truncate?
- Next by thread: Re: A simple debugging macro
- Index(es):
Relevant Pages
|