Optional per-line prefix for trace-macroexpand

:: lisp, releases

My macroexpansion tracer can now print per-line prefixes when tracing, which can make things more readable.

I find trace-macroexpand pretty useful: if you write Lisp with lots of nontrivial macros1 then it can be fairly hard to understand what’s going on when something is not working properly. trace-macroexpand lets you see this either for individual macros or many of them. It can, portably, trace any macro including ones defined by CL, which is even nicer.

However it’s not always easy to distinguish its output from other output. So, I realised I could add a per-line prefix which can help distinguish its output. Here is an example.

> (defvar *a* (cons nil nil))
*a*

> (trace-macroexpand t)
nil

> (trace-macro setf)
(setf)

> (setf (car *a*) 10)
(setf (car *a*) 10)
 -> (system::%rplaca *a* 10)
10

> (setf *trace-macroexpand-per-line-prefix* "| ")
(setf *trace-macroexpand-per-line-prefix* "| ")
 -> (let* (#) (setq *trace-macroexpand-per-line-prefix* #:|Store-Var-1692|))
"| "

> (setf (car *a*) 11)
| (setf (car *a*) 11)
|  -> (system::%rplaca *a* 11)
11

This is in version 10.8.12 of the TFEB.ORG Lisp hax, git repo.


  1. If you aren’t doing that, why are you writing Lisp at all? 

  2. 10.8.0 had a stupid bug.