If an error occurs during the expansion of a macro, Gambit doesn't start a new repl to enable me to debug the code. Is there a way to enable this? It would be really helpfull for me as some of my macros are really complex.
For instance:
Gambit Version 4.0 beta 22
(define-macro (foo) (car 1)) (foo)
*** ERROR -- (Argument 1) PAIR expected (car 1)
Thanks,
Guillaume
Afficher les réponses par date
On Sat, Jun 09, 2007 at 12:32:32PM -0400, Guillaume Cartier wrote :
If an error occurs during the expansion of a macro, Gambit doesn't start a new repl to enable me to debug the code. Is there a way to enable this? It would be really helpfull for me as some of my macros are really complex.
gsi -:dar macro.scm should give you gambit's prompt after failing. (I don't really know what this option means or does, but I use it a lot :D)
Adrien
Thanks Adrien. I do get the prompt but with no backtrace available... e.g. ,b will not report the stack that lead to the problem inside the macro expander.
In the meantime though, I found out that simply wrapping the code I want to expand inside eval does the trick.
(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?
Thanks,
Guillaume
Adrien Pierard wrote:
On Sat, Jun 09, 2007 at 12:32:32PM -0400, Guillaume Cartier wrote :
If an error occurs during the expansion of a macro, Gambit doesn't start a new repl to enable me to debug the code. Is there a way to enable this? It would be really helpfull for me as some of my macros are really complex.
gsi -:dar macro.scm should give you gambit's prompt after failing. (I don't really know what this option means or does, but I use it a lot :D)
Adrien
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.