[plt-scheme] Macros and quasi-quotation

From: Zbyszek Jurkiewicz (zbyszek at duch.mimuw.edu.pl)
Date: Thu Feb 27 07:20:14 EST 2003

On Sun, 16 Feb 2003, Matthew Flatt wrote:

>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> 
> At Sun, 16 Feb 2003 00:11:42 +0100, Jens_Axel_Søgaard wrote:
> >   > (define-macro (a) 1)
> >   > (define-macro (b) (a))
> >   > (b)
> >   . reference to undefined identifier: a
> >   > (a)
> >   1
> > 
> > Is this intensional?
> 
> Yes. Expansion-time expressions cannot directly reference top-level
> bindings. (It's not just that MzScheme disallows it; the rules of
> binding scope prevent direct references.)
> 
> Matthew
> 
> 

But

> (define-syntax a (syntax-rules () ((a) 1)))
> (define-syntax b (syntax-rules () ((b) (a)))
)
> (b)
1

works perfectly.  The following also works
(module ma mzscheme
  (require (lib "defmacro.ss"))
  (provide (all-defined))
  (define-macro (a) 1))

(module mb mzscheme
  (require (lib "defmacro.ss"))
  (require-for-syntax ma)
  (provide (all-defined))
  (define-macro (b) (a)))

> (require mb)
> (b)
1

So it is possible to refer to "top-level bindings", but in
indirect and contrived way.

Zbyszek Jurkiewicz
 


Posted on the users mailing list.