[plt-scheme] scope of module exports

From: Jon Rafkind (workmin at ccs.neu.edu)
Date: Tue Dec 12 14:07:52 EST 2006

I came across a, what I thought, strange situation with macros and 
modules. If I provide an identifier that was created with 
datum->syntax-object with macro A and define that identifier with macro 
B then the module system will complain that the identifier is not 
provided by the module. Basically this doesn't work:

(module x1 mzscheme

(define-syntax (b1 stx)
  (syntax-case stx ()
    ((_) (with-syntax ((f (datum->syntax-object #'stx 'foo)))
       #'(define f 2)))))

(define-syntax (b2 stx)
  (syntax-case stx ()
    ((_) (with-syntax ((f (datum->syntax-object #'stx 'foo)))
       #'(provide f)))))

(b1)
(b2)
)
x.ss:1:0: module: provided identifier not defined or imported at: foo 
in: (#%plain-module-begin (require-for-syntax mzscheme) (define-syntax 
(b1 stx) (syntax-case stx () (...

I suppose because the provide statement in b2 doesn't see the variable 
that was defined in b1. But if the syntax expansion phase happens before 
the module evaluation phase then shouldn't this be ok? I guess I'm 
missing something.



Posted on the users mailing list.