On Aug 7, 2015, at 4:15 PM, Deren Dohoda <deren.doh...@gmail.com> wrote:
> I have a minimal example that reproduces the behavior and I can track it > down to the fact that I do not export "define" and the file which uses the > new #lang does not define anything, except through a #%module-begin rewrite. You shouldn't need a #%module-begin rewrite either though. (cont. below) > If the file written in the new #lang has access to define and defines > anything, then indeed it shows up. Please forgive any gmail formatting: > > TEST/ > --test.rkt > --test-lang/ > ----test-lang.rkt > ----lang/ > ------reader.rkt > > I add the TEST directory to PLTCOLLECTS. > > reader.rkt: > #lang s-exp syntax/module-reader > "test-lang/test-lang.rkt" > > test-lang.rkt: > #lang racket/base > (provide (rename-out (my-module-begin #%module-begin)) > #%app #%top #%datum #%top-interaction > require displayln) > > (define-syntax-rule (my-module-begin body ...) > (#%module-begin > (define x 2) > (provide x) > body ...)) I don't think that's what you want to do. What you probably want is this: test-lang.rkt: #lang racket/base (provide #%module-begin ; from racket/base #%app #%top #%datum #%top-interaction require displayln x) (define x 2) Then the repl for test.rkt should work. (cont. below) > test.rkt: > #lang test-lang > (displayln 2) > > Run "test.rkt" > Welcome to DrRacket, version 6.2 [3m]. > Language: test-lang [custom]; memory limit: 4096 MB. > 2 > > x > . . x: undefined; > cannot reference an identifier before its definition > > (require "test.rkt") > > x > 2 > ;;;;;;;;;;;;;;;;;;;;; > > It seems to be because of the definition of x in my-module-begin. But I don't > understand why this doesn't work. 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) 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) 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) body ...))]))) Hope this helps! Alex Knauth > Thanks for any insight here, I seem to have a bad mental model of what's > happening, > Deren > > > On Fri, Aug 7, 2015 at 4:32 PM, Alexander D. Knauth <alexan...@knauth.org> > wrote: > That sounds weird. You shouldn't need to do anything special with > #%top-interaction or anything, so I'm not sure what's going on. > > How are you defining it? Can you show us some of the source code? > > On Aug 7, 2015, at 1:09 PM, Deren Dohoda <deren.doh...@gmail.com> wrote: > > > I have a #lang I'm working on and everything seems to be going very well. > > One thing I don't understand, though, is that when a file written in this > > language is opened in DrRacket and Run, I still have to (require > > "file.rkt") in the REPL before I am able to use anything provided by the > > file. > > > > I assume that I am neglecting to do something somewhere related to the use > > of #%top-interaction, because when I fail to provide this from the > > implementation of the language, I cannot run the file in DrRacket at all. > > But merely adding it to the provide expression doesn't do what I expect. > > > > Any help? > > > > Deren > > > > -- > > 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.