Short version: __Thank you__ It does appear that I do not need the #%module-begin rewrite in this test case. However, the point of the language is to create a dictionary of procedures and provide a "run" procedure which accepts a symbol and returns the procedure in the dictionary. My concern was what would happen if multiple files of this language were required at one time, that the dictionary would contain references to all these functions, which might have the same key. So, I thought I had to put the dictionary and run procedures in the %#module-begin rewrite. If I eliminate the #%module-begin rewrite, then multiple files will add their procedures to the same underlying dictionary which could cause an unnecessary collision in a practical example.
But, that's a long way to say that you are right, the problem was naming scope. After using a with-syntax rewrite then it is behaving as expected in the REPL. Thanks for your help. Deren On Fri, Aug 7, 2015 at 5:45 PM, Alexander D. Knauth <alexan...@knauth.org> wrote: > > On Aug 7, 2015, at 4:35 PM, Alexander D. Knauth <alexan...@knauth.org> > wrote: > > The definition of x in `my-module-begin` doesn't work because it comes > from the macro's scope, not from the module's scope. > See > http://docs.racket-lang.org/reference/syntax-model.html#%28part._macro-introduced-bindings%29 > > If you really need to use that approach instead of what I suggested above, > you should be able use either syntax-local-introduce or datum->syntax. > You could try building off of one of these: (not tested) > > (require syntax/parse/define) > ;; one option, using syntax-local-introduce: > (define-simple-macro (my-module-begin body ...) > #:with x-id (syntax-local-introduce #'x) > (#%module-begin > (define x 2) > > > Sorry I meant (define x-id 2) > > body ...)) > ;; another option, using syntax-local-introduce: > (define-syntax my-module-begin > (lambda (stx) > (syntax-case stx () > [(_ body ...) > (with-syntax ([x-id (syntax-local-introduce #'x)]) > #'(#%module-begin > (define x 2) > > > And here too, (define x-id 2) > > body ...))]))) > ;; another option, using datum->syntax: > (define-syntax my-module-begin > (lambda (stx) > (syntax-case stx () > [(_ body ...) > (with-syntax ([x-id (datum->syntax stx 'x)]) > #'(#%module-begin > (define x 2) > > > And here, (define x-id 2) > > body ...))]))) > > Hope this helps! > > Alex Knauth > > > -- 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.