On this page:

1.7 API for Simple Bytecode Creation

 (require compiler/compile-file) package: base


(compile-file src [dest filter])  path?

  src : path-string?
  dest : path-string?
(let-values ([(base name dir?) (split-path src)])
  (build-path base "compiled"
              (path-add-suffix name #".zo")))
  filter : (any/c . -> . any/c) = values
Compiles the Racket file src and saves the compiled code to dest. If dest is not provided and the "compiled" subdirectory does not already exist, the subdirectory is created. The result of compile-file is the destination file’s path.

If the filter procedure is provided, it is applied to each source expression, and the result is compiled.

Beware that compile-file uses the current reader parameterization to read src. Typically, compile-file should be called from a thunk passed to with-module-reading-parameterization so that the source program is parsed in a consistent way and allowing #lang.

Each expression in src is compiled independently. If src does not contain a single module expression, then earlier expressions can affect the compilation of later expressions when src is loaded directly. An appropriate filter can make compilation behave like evaluation, but the problem is also solved (as much as possible) by the compile-zos procedure.

See also managed-compile-zo.