You can't define the reader part of a #lang in the same file and then use it, but you can definitely define the bindings, from things like #%module-begin and #%app on up, and use it in the same file. The following works fine for me:
#lang racket (module greeting racket (provide #%module-begin) (require (for-syntax syntax/parse)) (define-syntax #%module-begin (syntax-parser [(_ one:str two:str) #'(#%plain-module-begin (printf "Hello, ~a!\n" 'one) (printf "Salutations, ~a!\n" 'two))]))) (module main (submod ".." greeting) "Santa Claus" "Easter Bunny") Carl Eastlund On Mon, Dec 3, 2012 at 3:46 PM, Stephen Chang <stch...@ccs.neu.edu> wrote: > When doing quick experiments, I've often wanted the ability to define > a new language and then use it in the same file. I thought submodules > might allow me to do this, but I've realized that I still can't. > However, in trying to do so I ran into some interesting behavior: > > > Here is a file named test.rkt that is saved to disk: > > #lang racket > > (define-syntax-rule (app x ...) (begin (displayln "hello") (#%app x > ...))) > > (provide (except-out (all-from-out racket) #%app) > (rename-out [app #%app])) > > > If I then add to the same file: > > (module test "test.rkt" (+ 1 2)) > > but *don't* save, pressing run in drracket displays: > > Welcome to DrRacket, version 5.3.1.1 [3m]. > Language: racket [custom]. > hello > 3 > > > > > Then if I save and run again, I get an error: > > Welcome to DrRacket, version 5.3.1.1 [3m]. > Language: racket [custom]. > . . ../plt/collects/compiler/cm.rkt:350:0: > standard-module-name-resolver: cycle in loading > at path: /home/stchang/tmp/test.rkt > paths: > /home/stchang/tmp/test.rkt > > > > > Is this the intended behavior? I guess this is what I would expect but > it feels funny since an identical buffer produces different output > depending on it's saved status. > _________________________ > Racket Developers list: > http://lists.racket-lang.org/dev > >
_________________________ Racket Developers list: http://lists.racket-lang.org/dev