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