[gambit-list] Debugging define-macros

Etienne Laurin laurieti at iro.umontreal.ca
Fri Oct 26 12:02:20 EDT 2007


Hi,

You can use this code to trace the expansion of your macros:

(##define-macro
 (define-macro args . body)
 (let ((all (gensym)))
   `(##define-macro
     (,(car args) . ,all)
     (let ((exp (apply (lambda ,(cdr args) . ,body) ,all)))
       (pp (list (cons ',(car args) ,all) '-> exp))
       exp))))

For example:

> (define-macro (when c . e) `(if ,c (begin . ,e)))
> (when #t (when #f (pp 'foo)) 2)
((when #t (when #f (pp 'foo)) 2) -> (if #t (begin (when #f (pp 'foo)) 2)))
((when #f (pp 'foo)) -> (if #f (begin (pp 'foo))))
2

Etienne Laurin


On Fri, Oct 26, 2007 at 08:49:15AM -0400, Christopher Diggins wrote:
> I was wondering if anyone could suggest a method of debugging
> "define-macro" expressions so that I can see what is actually being
> generated by the macro system (e.g. by preventing evaluation of the
> resulting macro, and printing it)? Otherwise I get a cryptic messages
> like "unbound unquote", and "ill-formed expression", but without any
> hints what is causing the grief in the generated code.
> 
> Thanks,
> Christopher Diggins
> _______________________________________________
> Gambit-list mailing list
> Gambit-list at iro.umontreal.ca
> https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list



More information about the Gambit-list mailing list