[gambit-list] Expanding Macros

Christian christian at pflanze.mine.nu
Thu Nov 23 19:06:31 EST 2006


At 22:30 Uhr +0000 22.11.2006, Mark Smith wrote:
>Hi guys,
>
>First time on the mailing list, or any mailing list for that matter. I
>have a very simple question about macros if someone would fill me in:
>how do I expand a macro like you can in Common Lisp or some other
>Scheme implementations?

See the mailing list archive,
https://webmail.iro.umontreal.ca/pipermail/gambit-list/2005-August/000326.html

Writing your own macro system *is* an option, of course, if you 
really want to and know how it should behave :). I'm in the process 
of doing this.

>I've been using the pp function but it complains under some situations
>i.e. when my macro expands into a definition.

For debugging during development, I'm usually printing the expansion 
from the expander code, like (written from memory, untested):

(define-macro (define-bothtimes . body)
   (eval `(define , at body))
   `(define , at body))

(define-bothtimes (pp-through val)
   (pp val)
   val)

;; (depending on whether the definition of pp-through is in a 
different file or not, a normal define or a define-compiletime would 
have sufficed, but define-bothtimes will work in both cases)

(define-macro (foo x y)
  (pp-through
    `(blabla ',x ',y)))

An alternative is to write and debug transformers as normal functions 
and call them from the macro code:

(define-bothtimes (foo-trans x y)
  `(blabla ',x ',y))

(define-macro (foo . args) (apply foo-trans args))

; (Notably, (define-macro foo foo-trans) won't work, and there's no 
easy operation I know of for doing this.)

Christian.



More information about the Gambit-list mailing list