I don't have a comprehensive answer, but, in this case, `define` comes from
`racket/base`, but the initial import of `racket/base` into the submodule
has macro-introduced scope, so it isn't visible to the `form`s. It is the
same principle as why this doesn't work:
(define-syntax-rule (in-x-context form ...)
(let ([x 42])
To fix it, you can give the import of `racket/base` the right lexical
(define-syntax (define-simple-module stx)
(syntax-case stx ()
[(_ name form ...)
#`(module name #,(datum->syntax stx 'racket/base)
(define shwarma 8.00)
(define falafel 6.50))
On Mon, Oct 9, 2017 at 11:19 PM, Milo Turner <iital...@gmail.com> wrote:
> Hi Racketeers.
> I'm writing some macro code that generates submodules. I'm not entirely
> sure how hygiene is maintained when creating submodules, and now I have
> little idea why my macros are doing the crazy things that they are. Could
> anyone give a concrete explanation on how modules work with hygiene, and
> perhaps as a motivating example, why does the following code break?
> #lang racket
> (define-syntax-rule (define-simple-module name form ...)
> (module name racket/base
> (provide (all-defined-out))
> form ...))
> (define-simple-module prices
> (define shwarma 8.00)
> (define falafel 6.50))
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
For more options, visit https://groups.google.com/d/optout.