Re: A simple debugging macro
- From: Rainer Joswig <joswig@xxxxxxx>
- Date: Fri, 30 Nov 2007 05:31:59 +0100
In article
<23a2fa9f-68ea-48f4-939a-a4bc040516c2@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
"fairchild.anthony@xxxxxxxxx" <fairchild.anthony@xxxxxxxxx> wrote:
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*
You have to recompile client code to switch tracing on or off.
`(progn (format *trace-output* "TRACE: ")
,(when (stringp (first vars))
Why just the first arg? Allow strings in all positions.
`(format *trace-output* "~A " ,(pop vars)))
FORMAT obsession. Inserting a string in a string and printing that.
,@(loop for var in vars
collect `(format *trace-output* "~A=~S "
',var ,var))
(format *trace-output* "~%" )
FORMAT obsession. TERPRI.
(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
--
http://lispm.dyndns.org/
.
- Follow-Ups:
- Re: A simple debugging macro
- From: fairchild.anthony@xxxxxxxxx
- Re: A simple debugging macro
- References:
- A simple debugging macro
- From: fairchild.anthony@xxxxxxxxx
- A simple debugging macro
- Prev by Date: A simple debugging macro
- Next by Date: Re: A simple debugging macro
- Previous by thread: A simple debugging macro
- Next by thread: Re: A simple debugging macro
- Index(es):
Relevant Pages
|