Discussion:
[racket] Read-syntax for an entire .rkt file
Thomas Gilray
2015-02-18 21:35:08 UTC
Permalink
Hi,

I am trying to figure out how to use read-syntax on a port for an entire
.rkt file. I want to then call (expand ...) on this and get back a (begin
...) or (module ...) form for the entire file in fully expanded form. Right
now I have three issues:

a) I have to skip over the #lang as this is not recognized by read-syntax
itself

b) I've needed to call read-syntax repeatedly to consume the whole file and
put each expression in a top-level begin (a pretty klugy workaround)

c) even then, calling expand will report an error that "define" is not
itself defined. Maybe there is a version of read-syntax that will use
read-language internally in the right way but I can't find it.

There is probably a way of doing all of this at once, and better, but I
don't know what that would be. I feel read-language is needed, but I don't
see how this would work together with read-syntax.

Any advice or pointers would be greatly appreciated!

--
Tom
Spencer Florence
2015-02-20 05:57:25 UTC
Permalink
What you want is `with-module-reading-parameterization
<http://docs.racket-lang.org/syntax/module-helpers.html?q=with-module-reading#%28def._%28%28lib._syntax%2Fmodread..rkt%29._with-module-reading-parameterization%29%29>
`:

(with-module-reading-parameterization
<http://docs.racket-lang.org/syntax/module-helpers.html?q=with-module-reading#%28def._%28%28lib._syntax%2Fmodread..rkt%29._with-module-reading-parameterization%29%29>
(lambda
() (read (open-input-port "my-file.rkt"))))
Post by Thomas Gilray
Hi,
I am trying to figure out how to use read-syntax on a port for an entire
.rkt file. I want to then call (expand ...) on this and get back a (begin
...) or (module ...) form for the entire file in fully expanded form. Right
a) I have to skip over the #lang as this is not recognized by read-syntax
itself
b) I've needed to call read-syntax repeatedly to consume the whole file
and put each expression in a top-level begin (a pretty klugy workaround)
c) even then, calling expand will report an error that "define" is not
itself defined. Maybe there is a version of read-syntax that will use
read-language internally in the right way but I can't find it.
There is probably a way of doing all of this at once, and better, but I
don't know what that would be. I feel read-language is needed, but I don't
see how this would work together with read-syntax.
Any advice or pointers would be greatly appreciated!
--
Tom
____________________
http://lists.racket-lang.org/users
Loading...