[R6RS] modules
R. Kent Dybvig
dyb
Mon Aug 23 10:50:10 EDT 2004
> (module M (x get-x)
> (require M)
> (define x 5)
> (define (get-x) #'x))
Is the (require M) above a mistake or does it do something special that
is somehow germaine to your question? I'll assume you meant
(module M (x get-x)
(define x 5)
(define (get-x) #'x))
but correct me if I'm wrong.
> (module N (def-f-fun def-f-mac)
> (require only-for-syntax M)
> (define-syntax def-f-mac
> (lambda (stx)
> (with-syntax ((x2 (get-x)))
> #'(define-syntax f (lambda (stx) x2)))))
> (define-syntax def-f-fun
> (lambda (stx)
> (with-syntax ((x2 (get-x)))
> #'(define f (lambda (stx) x2))))))
> I expect that either `def-f-mac' or `def-f-fun' always works, and the
> other never works. But which one (if either)?
def-f-fun should fail because it produces a run-time reference to a
variable---M's x---that is available only at expansion time.
I don't see any reason why def-f-mac should fail. M's x is used only
for syntax, as required.
Incidentally, I hope we agree that no one can use def-f-mac's product
in any case, since f is an introduced identifier with no references.
(The same was true in your earlier example.) But this variant should
also work:
(module N (def-f-mac)
(require only-for-syntax M)
(define-syntax def-f-mac
(lambda (stx)
(syntax-case stx ()
[(_ f) (with-syntax ((x2 (get-x)))
#'(define-syntax f (lambda (stx) x2)))]))))
(require N)
(def-f-mac high)
high ;-> 5
Kent
More information about the R6RS
mailing list