[racket] read-syntax for an entire .rkt file
There is also a `with-module-reading-parameterization` that sets up the
reader to do this.
On Wed, Feb 18, 2015, 10:36 PM Sam Tobin-Hochstadt <samth at cs.indiana.edu>
wrote:
> On Wed, Feb 18, 2015 at 10:22 PM, Thomas Gilray <thomas.gilray at gmail.com>
> wrote:
> > Hi everyone,
> >
> > I am trying to figure out how to use read-syntax on a port for an entire
> > .rkt file. I then want to call (expand ...) on this and get back a (begin
> > ...) or (module ...) for the entire file in fully expanded form.
> >
> > If I run (expand #`(define ...)) under a #lang racket, everything works.
> If
> > I place this in a file and use read-syntax however, each top-level
> > expression is returned individually, the language declaration isn't
> > supported, and without this information the expander complains that
> "define"
> > isn't defined. How do I properly read-syntax a whole file at once?
> >
> > Any ideas would be greatly appreciated.
>
> I've implemented this a couple times recently, probably the best
> version is here:
> https://github.com/samth/pycket/blob/master/pycket/pycket-lang/expand.rkt
>
> The short answer is that you want to use `read-accept-lang` to enable
> #lang, call `read-syntax` once on the port, and the call `expand` in a
> new namespace (probably created with `make-base-namespace`).
>
> Sam
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20150219/c578e352/attachment-0001.html>