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
Afficher les réponses par date
Your friends here are lambda and pp. Gambit will always expand macros inside a lambda so if you have file x.scm containing :
------------
(define-macro (when test body) `(if ,test (begin ,@body)))
(define (foo x) (when (= x 0) (write 'yo))) ------------
you can do the following
Gambit v4.0.0
(load "x")
"C:\Jazz\dev\jazz\x.scm"
(pp foo)
(lambda (x) (if (= x 0) (begin write 'yo)))
alternatively, if your code is compiled, I suggest always compiling it with -debug that adds no runtime penalty and keeps the source code so you can do
C:\Jazz\dev\jazz>gsc -debug x
C:\Jazz\dev\jazz>gsc Gambit v4.0.0
(load "x")
"C:\Jazz\dev\jazz\x.o1"
(pp foo)
(##lambda (x) (when (= x 0) (write 'yo)))
Guillaume On 10/26/07, Christopher Diggins cdiggins@gmail.com 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@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
While reading my post I noticed that (pp foo) will not have the macros expanded in the compiled version. Of course, the Gambit compiler preserves the copy of the source code *before* doing macro expansions so it is exactly as in the source file. Sorry about that. Guess what that means is that the interpreter is your other friend ;)
On 10/26/07, Guillaume Cartier gcartier@jazzscheme.org wrote:
Your friends here are lambda and pp. Gambit will always expand macros inside a lambda so if you have file x.scm containing :
(define-macro (when test body) `(if ,test (begin ,@body)))
(define (foo x) (when (= x 0) (write 'yo)))
you can do the following
Gambit v4.0.0
(load "x")
"C:\Jazz\dev\jazz\x.scm"
(pp foo)
(lambda (x) (if (= x 0) (begin write 'yo)))
alternatively, if your code is compiled, I suggest always compiling it with -debug that adds no runtime penalty and keeps the source code so you can do
C:\Jazz\dev\jazz>gsc -debug x
C:\Jazz\dev\jazz>gsc Gambit v4.0.0
(load "x")
"C:\Jazz\dev\jazz\x.o1"
(pp foo)
(##lambda (x) (when (= x 0) (write 'yo)))
Guillaume On 10/26/07, Christopher Diggins cdiggins@gmail.com 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@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
Thank you very much for your prompt help Guillaume and David.
- Christopher
On 10/26/07, Guillaume Cartier gcartier@jazzscheme.org wrote:
While reading my post I noticed that (pp foo) will not have the macros expanded in the compiled version. Of course, the Gambit compiler preserves the copy of the source code *before* doing macro expansions so it is exactly as in the source file. Sorry about that. Guess what that means is that the interpreter is your other friend ;)
On 10/26/07, Guillaume Cartier gcartier@jazzscheme.org wrote:
Your friends here are lambda and pp. Gambit will always expand macros
inside a lambda so if you have file x.scm containing :
(define-macro (when test body) `(if ,test (begin ,@body)))
(define (foo x) (when (= x 0) (write 'yo)))
you can do the following
Gambit v4.0.0
(load "x")
"C:\Jazz\dev\jazz\x.scm"
(pp foo)
(lambda (x) (if (= x 0) (begin write 'yo)))
alternatively, if your code is compiled, I suggest always compiling it
with -debug that adds no runtime penalty and keeps the source code so you can do
C:\Jazz\dev\jazz>gsc -debug x
C:\Jazz\dev\jazz>gsc Gambit v4.0.0
(load "x")
"C:\Jazz\dev\jazz\x.o1"
(pp foo)
(##lambda (x) (when (= x 0) (write 'yo)))
Guillaume
On 10/26/07, Christopher Diggins <cdiggins@gmail.com > 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@iro.umontreal.ca
https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
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@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list