Re: [racket-users] Submodules & Hygiene
Milo, think of the ***s in (module name *** ..) as a ‘defining’ position. It is the first ‘require’ of a module after all. Their scope conflicts with the scope of the macro-defined thingies and Philip’s “trick” unifies the scope. But having said this, I have fallen for it too. > On Oct 10, 2017, at 12:35 AM, Philip McGrath wrote: > > 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: > > #lang racket > (define-syntax-rule (in-x-context form ...) > (let ([x 42]) > form ...)) > > (in-x-context x) > > To fix it, you can give the import of `racket/base` the right lexical context > manually: > > #lang racket > > (define-syntax (define-simple-module stx) > (syntax-case stx () > [(_ name form ...) > #`(module name #,(datum->syntax stx 'racket/base) > (provide (all-defined-out)) > form ...)])) > > (define-simple-module prices > (define shwarma 8.00) > (define falafel 6.50)) > > (require 'prices) > > shwarma > > -Philip > > On Mon, Oct 9, 2017 at 11:19 PM, Milo Turner 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)) > > > Milo > > -- > 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 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 to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] Submodules & Hygiene
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: #lang racket (define-syntax-rule (in-x-context form ...) (let ([x 42]) form ...)) (in-x-context x) To fix it, you can give the import of `racket/base` the right lexical context manually: #lang racket (define-syntax (define-simple-module stx) (syntax-case stx () [(_ name form ...) #`(module name #,(datum->syntax stx 'racket/base) (provide (all-defined-out)) form ...)])) (define-simple-module prices (define shwarma 8.00) (define falafel 6.50)) (require 'prices) shwarma -Philip On Mon, Oct 9, 2017 at 11:19 PM, Milo Turner 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)) > > > Milo > > -- > 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 to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[racket-users] Submodules & Hygiene
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)) Milo -- 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.