Reading and expanding a Racket source file
<p>I need to read a Racket source file and run it through macro expansion. I have a simple test file that Racket itself happily accepts:</p>

<pre><code>C:\ayane&gt;type factorial.rkt
#lang racket
(provide factorial)

(define (factorial n)
 (if (&lt;= n 1)
  1
  (* n (factorial (sub1 n)))))
</code></pre>

<p>Now I try from the REPL:</p>

<pre><code>C:\ayane&gt;racket
Welcome to Racket v6.5.
&gt; (read-accept-reader #t)
&gt; (expand (with-input-from-file "factorial.rkt" (lambda () (read-syntax "factorial.rkt"))))
#&lt;syntax::1 (module factorial racket (#%m...&gt;
</code></pre>

<p>So far so good. Now the same thing from a test program:</p>

<pre><code>C:\ayane&gt;type test.rkt
#lang racket
(read-accept-reader #t)
(expand (with-input-from-file "factorial.rkt"
                              (lambda ()
                               (read-syntax "factorial.rkt"))))

C:\ayane&gt;racket test.rkt
factorial.rkt::1: module: unbound identifier;
 also, no #%app syntax transformer is bound
  at: module
  in: (module factorial racket (#%module-begin (provide factorial) (define (factorial n) (if (&lt;= n 1) 1 (* n (factorial (sub1 n)))))))
  context...:
   C:\ayane\test.rkt: [running body]
</code></pre>

<p>So it looks like the same code works interactively but not in a program. What am I missing?</p>