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.

Reply via email to