Re: A simple debugging macro



On Nov 30, 8:34 am, Ken Tilton <kennytil...@xxxxxxxxxxxxx> wrote:
fairchild.anth...@xxxxxxxxx wrote:
Here's a macroexpand:

CL-USER> (pprint (macroexpand-1 '(print-vars "before" a b c "after")))

(PROGN
(WRITE-STRING "TRACE: " *TRACE-OUTPUT*)
(PROGN (WRITE-STRING "before") (WRITE-STRING " "))
(FORMAT *TRACE-OUTPUT* "~A=~S " 'A A)
(FORMAT *TRACE-OUTPUT* "~A=~S " 'B B)
(FORMAT *TRACE-OUTPUT* "~A=~S " 'C C)
(PROGN (WRITE-STRING "after") (WRITE-STRING " "))
(TERPRI *TRACE-OUTPUT*)
(FINISH-OUTPUT *TRACE-OUTPUT*))
; No value

Which reminds me, you probably want the expnasion to be:

(call-print-vars "before" a b c "after")


Assuming CALL-PRINT-VARS is a function, wouldn't PRINT-VARS need to
expand to:

(call-print-vars "before" :a a :b b :c c "after")

Also, this case needs to be handled:

(print-vars (length my-list))

expands to:

(call-print-vars :|(length my-list)| (length my-list))

And would print:

TRACE: (LENGTH MY-LIST)=12

Is this correct or am I missing something?

...and with mine, if the first arg is a hard-coded nil (not a form which
might evaluate to nil at runtime, which would mean "do not emit this
time") the expansion is:

(progn)

Makes it quick and easy to disable/re-enable debug stuff I suspect will
be needed again.

Thanks again! Now I'm off to look at kenny's suggestions.

If you like them you might want to start from the stuff in utils-kt.
Less often needed but great when needed is a with-trc macro that wraps a
possibly recursively invoked form such that output is indented to
reflect recursion depth.

Another favorite of mine is

(with-metrics <counts?> <timing?> <insert usual trc args> &body)

timing being t causes the form to be wrapped in (time ), counts being t
invokes a counting utility, initializing it, running the body, and then
dumping the count results. counting is easy:

(count-it :hi-mom)

or

(count-it :color-change this-color)

the latter giving you a histogram by color value.


This is very useful to me, I'll look at your utils-kt and see what I
can cook up with this.

.