Normally, compilation happens automatically: when an S-expression is evaluated, it is first compiled and then the compiled code is executed. However, MzScheme can also write and read compiled MzScheme code. MzScheme can read compiled code somewhat faster than reading S-expression code and compiling it, so compilation can be used to speed up program loading. The procedure compile-file is sufficient for most compilation purposes.
(compile-file src dest expand-load?)
compiles the Scheme file src and saves the compiled code to
dest. The src and dest arguments are usually
filenames
; src can also be an input port and dest can
be an output port. If an input or output port is provided, the port is
not closed when compilation is finished.
If dest is a filename and the file already exists,
it is replaced.
The expand-load? argument is an optional argument that defaults to #f; if it is not #f, then top-level load, load-with-cd, and load/cd statements in the src file are expanded and compiled into dest.
All macros used in the source file must either be defined at compile-time, defined using a top-level define-macro statement in the source file (or in an loaded file that is expanded), or defined locally in a let-macro expression.
(compile expr) compiles expr, where expr is any S-expression that can be passed to eval. The result is a compiled expression Scheme value. This value is passed to eval to evaluate the compiled expression.
When a compiled expression is written, it starts with #`. These expressions are essentially assembly code for the MzScheme interpreter. Never ask MzScheme to evaluate an expression starting with #` unless compile generated the expression. To keep users from accidentally specifying bad instructions, read will not accept expressions beginning with #` unless it is specifically enabled. (read-accept-compiled) returns #t if read currently allows compiled expressions, or #f otherwise. (read-accept-compiled on?) disables compiled expression reading if on? is #f, or enables it otherwise. While the load procedure is used to load a file, compiled expression reading is automatically enabled.