[gambit-list] macros talking to each other
Marc Feeley
feeley at iro.umontreal.ca
Wed Jul 8 15:50:28 EDT 2009
On 8-Jul-09, at 2:51 PM, lowly coder wrote:
> Is it possible to define macros foo & bar so that the following code:
>
> (foo '(1 2 3))
>
> ... some junk ...
>
> (bar)
>
> becomes, at compile time:
>
> '()
>
> ... some junk ...
>
> '(1 2 3)
>
>
> -- the real question being, right now, each macro expansion seems to
> happen in it's own little world -- is there anyway they can
> communicate?
There are several forms of shared state that can be used for such
communication, the simplest one is the global variables (another is
the file system, another is TCP/IP, ...). Here's an example:
(define-macro (at-expansion-time expr)
(eval expr)
`(begin))
(at-expansion-time (define gv #f))
(define-macro (foo expr)
(set! gv expr)
''())
(define-macro (bar)
gv)
(foo '(1 2 3))
(bar)
Marc
More information about the Gambit-list
mailing list