Re: A simple debugging macro



On Nov 29, 8:31 pm, Rainer Joswig <jos...@xxxxxxx> wrote:
In article
<23a2fa9f-68ea-48f4-939a-a4bc04051...@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,



"fairchild.anth...@xxxxxxxxx" <fairchild.anth...@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.


That was the intent of the macro, to allow the user to completely
compile-out the trace statements while leaving them in the code (thus
requiring a recompile of everything). I actually don't use this
feature, so I'll take it out. I usually just remove the PRINT-VARS
after I'm done debugging.

`(progn (format *trace-output* "TRACE: ")
,(when (stringp (first vars))

Why just the first arg? Allow strings in all positions.


This is a very good suggestion, I'll change the macro to handle it.


`(format *trace-output* "~A " ,(pop vars)))

FORMAT obsession. Inserting a string in a string and printing that.


Good point. I use used FORMAT because I was printing the string
followed by a space. Perhaps I should use WRITE-STRING followed by
PRINC?

,@(loop for var in vars
collect `(format *trace-output* "~A=~S "
',var ,var))
(format *trace-output* "~%" )

FORMAT obsession. TERPRI.



Excellent, this is exactly what I was looking for, good criticism. My
inexperience is showing ;-)

Thanks for your input. I'll rewrite it and post an update



(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/

.



Relevant Pages

  • Re: A simple debugging macro
    ... I wrote this simple macro a while back and I've found it to be ... extremely useful for old-fashioned trace style debugging. ... Inserting a string in a string and printing that. ... TRACE: before fib loop A=10 ...
    (comp.lang.lisp)
  • Compile-time text/string manipulation
    ... A "compile-time language" is one that processes ... Compile time languages for assemblers ... This group includes macro ... requires access to various string and text manipulation ...
    (alt.lang.asm)
  • RE: Search email for text string to use in filename - save email t
    ... The code for my macro is below. ... .MatchWholeWord = False ... Dim sNewFileName As String ... > 0 Then Exit Function ...
    (microsoft.public.outlook.program_vba)
  • Re: Document Property to display more than 1 line
    ... then use the following macro to identify the character ... Dim strNums As String ...
    (microsoft.public.word.newusers)
  • A simple debugging macro
    ... I wrote this simple macro a while back and I've found it to be ... extremely useful for old-fashioned trace style debugging. ... (defmacro print-vars (&rest vars) ... TRACE: before fib loop A=10 ...
    (comp.lang.lisp)