[gambit-list] macro debugging

Christian christian at pflanze.mine.nu
Sun Aug 7 18:22:00 EDT 2005


Hello

For some reason, errors in macro expansion don't trigger the
debugger. This may be on purpose, but it makes macro debugging
difficult. Gladly, I've found a workaround: run

 (current-exception-handler primordial-exception-handler)

before expansion of the faulty macro, or

 (with-exception-handler primordial-exception-handler
         (eval '(code-containing-calls-to-faulty-macro)))

but using eval disconnects the code from the lexical environment.

Now I'm looking for a simpler way to turn macro debugging on. I've
thought about a macro; since using eval is out of question (because of
breaking lexical env), I wanted to work around this by saving and
restoring the current handler manually:

(define-macro (cj-env#insert-result-of expr)
  (eval expr))

(define-macro (with-macro-debugging body)
  `(begin
     (cj-env#insert-result-of
      (begin
        (define |  saved-exception-handler| (current-exception-handler))
        (warn "saved:" |  saved-exception-handler|)
        (current-exception-handler primordial-exception-handler)
        (warn "now is:" (current-exception-handler))
        '(begin)))
     ,body
     (cj-env#insert-result-of
      (begin
        (warn "put back:" |  saved-exception-handler|)
        (current-exception-handler |  saved-exception-handler|)
        (warn "now is:" (current-exception-handler))
        '(begin))))))

But this won't work because the macro call after ,body isn't allowed,
see my former mail about (begin).

What are your suggestions?

Cheers
Christian.



More information about the Gambit-list mailing list