<div dir="ltr"><div><div><div>Thank you both for your help! This is what I ended up with:<br><br><span style="font-family:monospace,monospace">(define port (open-input-file "..."))<br>(with-module-reading-parameterization <br>  (lambda () <br>    (pretty-print (syntax->datum (parameterize ([current-namespace (make-base-namespace)])<br>                                   (expand (read-syntax (object-name port) port)))))))<br></span><br></div>I apologize for sending out two different emails on the same question. I had sent one before subscribing and thought it was discarded when it was actually only queued for approval.<br></div><br>--<br></div>Tom<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Feb 18, 2015 at 8:49 PM, Spencer Florence <span dir="ltr"><<a href="mailto:spencer@florence.io" target="_blank">spencer@florence.io</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">There is also a `with-module-reading-parameterization` that sets up the reader to do this.</p>
<br><div class="gmail_quote"><div><div class="h5">On Wed, Feb 18, 2015, 10:36 PM Sam Tobin-Hochstadt <<a href="mailto:samth@cs.indiana.edu" target="_blank">samth@cs.indiana.edu</a>> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">On Wed, Feb 18, 2015 at 10:22 PM, Thomas Gilray <<a href="mailto:thomas.gilray@gmail.com" target="_blank">thomas.gilray@gmail.com</a>> wrote:<br>
> Hi everyone,<br>
><br>
> I am trying to figure out how to use read-syntax on a port for an entire<br>
> .rkt file. I then want to call (expand ...) on this and get back a (begin<br>
> ...) or (module ...) for the entire file in fully expanded form.<br>
><br>
> If I run (expand #`(define ...)) under a #lang racket, everything works. If<br>
> I place this in a file and use read-syntax however, each top-level<br>
> expression is returned individually, the language declaration isn't<br>
> supported, and without this information the expander complains that "define"<br>
> isn't defined. How do I properly read-syntax a whole file at once?<br>
><br>
> Any ideas would be greatly appreciated.<br>
<br>
I've implemented this a couple times recently, probably the best<br>
version is here:<br>
<a href="https://github.com/samth/pycket/blob/master/pycket/pycket-lang/expand.rkt" target="_blank">https://github.com/samth/<u></u>pycket/blob/master/pycket/<u></u>pycket-lang/expand.rkt</a><br>
<br>
The short answer is that you want to use `read-accept-lang` to enable<br>
#lang, call `read-syntax` once on the port, and the call `expand` in a<br>
new namespace (probably created with `make-base-namespace`).<br>
<br>
Sam<br></div></div>
____________________<br>
  Racket Users list:<br>
  <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/<u></u>users</a><br>
</blockquote></div>
</blockquote></div><br></div>