[plt-scheme] enclosing-module-name

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Wed Apr 4 17:09:00 EDT 2007

At Wed, 4 Apr 2007 15:12:36 +0000, support at taxupdate.com wrote:
> On Wed, Apr 04, 2007 at 02:31:25PM -0400, Matthias Felleisen wrote:
> (module test mzscheme
>   (define-syntax (foo stx)
>     (syntax-case stx ()
>       ((_ exp)
>        (let ((prop (syntax-property stx 'enclosing-module-name)))
>          #`(printf "~a in module ~a" exp (quote #,prop))))))
> 
>   (define-syntax (template stx)
>     (syntax-case stx ()
>       ((_ name exp ...)
>        #`(module name mzscheme
>            (#%module-begin
>             (require test)
>             (provide (all-defined))
>             exp ...)))))
>    (provide (all-defined)))
> 
> (require test)
> (template a (foo 'a1))
> (require a)
> 
> This gives me "expand: unbound variable in module in: foo"
> 
> What am I missing here?

When a macro introduces a `require', then it binds hygienically. That
is, the introduced bindings are visible only from introduced references.


You could re-write as

   (define-syntax (template stx)
     (syntax-case stx ()
       ((_ req-id name exp ...)
        #`(module name mzscheme
            (#%module-begin
             (require req-id)
             (provide (all-defined))
             exp ...)))))
   ...

 (template test a (foo 'a1))

which will bind `foo' in the expected way, since the supplied name
`test' has the same lexical context as the reference `foo'.

But the result is still #f. An 'enclosing-module-name property is
attached only to `#%module-begin' forms, and `foo' is not playing the
role of `#%module-begin'.

Matthew



Posted on the users mailing list.