Next: Dynamic Extensions Up: Support Facilities Previous: Data Sharing in Input

# Compilation

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 MzLib procedure `compile-file` (see section 15.2.5) is sufficient for most compilation purposes.

- `(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 to an output port, the written form 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 through the `read-accept-compiled` Boolean parameter (see section 9.4.1.3). When the default load handler is used to load a file, compiled expression reading is automatically (temporarily) enabled as each expression is read.