[racket] Submodules vs hygiene
Yes, that's awkward. The problem is that the `quote` wrapper in
`(require (quote m))` is macro-introduced, and the whole `(quote m)`
form's context is used for the imported identifier.
In contrast, the variant
#lang racket
(define-syntax foo
(syntax-rules ()
((_ mod quoted-mod name)
(begin
(module mod racket/base
(define name 1)
(provide name))
(require quoted-mod)
name))))
(foo m 'm x)
works the way that you'd expect, because the whole
'm
is supplied to the macro for using in `require`.
At Tue, 21 Oct 2014 13:19:35 -0500, Brian Mastenbrook wrote:
> I am more than a little confused by the behavior of macros that expand to
> submodules. In the following example, I don't have any introduced names, but
> the `x' binding created by the submodule is not usable from the enclosing
> module. What confuses me even further is that if I (require (rename-in 'mod
> [name name])) instead, it works; I would expect that to always be a no-op. Can
> anyone explain this behavior?
>
> #lang racket
>
> (define-syntax foo
> (syntax-rules ()
> ((_ mod name)
> (begin
> (module mod racket/base
> (define name 1)
> (provide name))
> (require 'mod)
> name))))
>
> (foo m x)
>
> ==> x: unbound identifier in module in: x
>
> --
> Brian Mastenbrook
> brian at mastenbrook.net
> http:/brian.mastenbrook.net/
>
>
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users