On 27-Jan-09, at 2:34 PM, eryiling wrote:
suppose I have:
(define-macro (foo ...))
the standard way to 'debug' this is to do:
(pp (lambda () (foo ...)))
however, this requires that (foo ...) expands to proper scheme code (i.e. not things like "(a b . c)"), and also code that has well defined semantic meaning (i.e. no undefined vars)
as i write macros, i find that most of the time (in fact, except for the starting point and the ending point), my macro expansion offten results in non-scheme code; is there a way i can see this output? i.e. I wnat to see:
(macroexpand '(foo ...))
rather than the particular error for why (foo ... ) does not expand to legit scheme code
thanks!
Here's the trick I often use. Say you have the macro definition:
(define-macro (foo x y) ...something...)
you simply add a (list 'quote ...) around the body of your macro:
(define-macro (foo x y) (list 'quote ...something...))
Then when you can do
(pp (foo 1 2))
and this will print the s-expression that ...something... generated.
For example:
% gsi Gambit v4.4.0
(define-macro (bind var val expr)
(list 'quote `(let ((,var ,val)) ,expr)))
(pp (bind x (+ 1 2) (* x x)))
(let ((x (+ 1 2))) (* x x))
Once you are done debugging, you strip off the (list 'quote ...) wrapper.
Marc