[gambit-list] Debugging macros

Adrien Pierard pierarda at iro.umontreal.ca
Sat Jun 9 15:43:49 EDT 2007


On Sat, Jun 09, 2007 at 02:34:27PM -0400, Guillaume Cartier wrote :
> (foo) -> no backtrace available
> (eval '(foo)) -> it works!
> Marc, can you tell us if this trick of wrapping eval the macro is clean 
> and why it works?

I guess that it happens so because the macro expansion and the code
evaluation happen at two different stages.

(define-macro(foo)
  (begin
      (pp "macro")
          '(pp 42)))

(pp 41)
(foo)
(pp 43)


It your run the following code, the sentence "macro" prints *before* the
number 41, but 42 gets printed at the right place.

You have no backtrace yet because it expects a trace of the evaluation
of your code, whereas it fails even before evaluating it in fact.
By using eval, I guess that you delay the macro expansion at your code's 
evaluation time, therefore letting the backtrace happen.

By the way, for this very reason, doing (eval '(foo)) fails at mine, for
when it gets evaluated, the macro has already disappeared...
But having the whole code (including the macro definition) inside an
eval then makes it debuggable, for the expansion is at code-evaluation
time
(eval '(begin
        (define-macro(foo)
         (begin
          (pp "macro")
          (car 1)
          '(pp 42)))
        (foo)))

I hope it answers your question and that Marc will nod :)

Adrien.

-- 
"I am not a Church numeral; I am a free variable!"
(The Scheme Underground)
For every complex problem, there is a solution that is simple, neat, and wrong.



More information about the Gambit-list mailing list