How does defmacro expansion in Scheme and Common Lisp work?
Posted: Sat Jan 10, 2009 4:08 pm
Hi, I've been trying to use a "defmacro" form in some Scheme code lately, and it appears that Scheme defmacro doesn't have access to run-time bindings (at least not in MzScheme or Gambit), so to get my macros to work in Gambit, I need to have a repl open and insert the run-time code before the defmacro code.
On the other hand, as far as I can gather, CL has no problem with using run-time bindings at macro-time to perform expansions.
So I'm a bit confused... Am I doing it wrong by trying to use run-time bindings in Scheme? Or maybe because CL uses defun to define functions that makes it possible to use them in macro definitions? If Scheme and CL do treat defmacro usage differently, could anyone tell me why? Is there a way I can use defmacro in Scheme as I can for CL? Finally, how do CL macros access these run time definitions without accidentally calling run-time code at compile-time?
Hope someone can help clear this up, I tried searching but it seems like one of those things which are hard to find the right search query for.
Thanks for any help and sorry for bombarding all these questions!
On the other hand, as far as I can gather, CL has no problem with using run-time bindings at macro-time to perform expansions.
So I'm a bit confused... Am I doing it wrong by trying to use run-time bindings in Scheme? Or maybe because CL uses defun to define functions that makes it possible to use them in macro definitions? If Scheme and CL do treat defmacro usage differently, could anyone tell me why? Is there a way I can use defmacro in Scheme as I can for CL? Finally, how do CL macros access these run time definitions without accidentally calling run-time code at compile-time?
Hope someone can help clear this up, I tried searching but it seems like one of those things which are hard to find the right search query for.
Thanks for any help and sorry for bombarding all these questions!