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?
Thanks!
Afficher les réponses par date
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