Next: Exiting Up: Support Facilities Previous: Support Facilities

# Eval and Load

`(eval expr)` evaluates the S-expression expr in the current namespace. (See section 9.3 and section 9.4.1.6 for more information about namespaces.)

`(load file-path)` evaluates each expression in the specified file using `eval`. The return value from `load` is the value of the last expression from the loaded file (or void if the file contains no expressions). If file-path is a relative pathname, then it is resolved to an absolute pathname using the current directory. Before the first expression of file-path is evaluated, the current `load-relative` directory (the value of the `current-load-relative-directory` parameter; see section 9.4.1.7) is set to the absolute pathname of the directory containing file-path; after the last expression in file-path is evaluated (or when the load is aborted), the `load-relative` directory is restored to its pre-`load` value.

`(load-relative file-path)` is like `load`, but when file-path is a relative pathname, it is resolved to an absolute pathname using the current `load-relative` directory rather than the current directory. If the current `load-relative` directory is `#f`, then `load-relative` is the same as `load`.

`(load/use-compiled file-path)` is like `load-relative`, but `load/use-compiled` also checks for `.zo` files (usually produced with `compile-file`; see section 15.2.5) and `.so` (Unix, BeOS, and MacOS) or `.dll` (Windows) files. The check for a compiled file occurs whenever file-path ends with a dotted extension of three characters or less (e.g., `.ss` or `.scm`) and when a `compiled` subdirectory exists in the same directory as file-path. A `.zo` version of the file is loaded if it exists directly in the `compiled` subdirectory. An `.so` or `.dll` version of the file is loaded if it exists within a `native` subdirectory of the `compiled` directory, in a deeper subdirectory as named by `system-library-subpath`. A compiled file is loaded only if its modification date is not older than the date for file-path. If both `.zo` and `.so` or `.dll` files are available, the `.so` or `.dll` file is used.

Multiple files can be combined into a single `.so` or `.dll` file by creating a special dynamic extension `_loader.so` or `_loader.dll`. When such a extension is present where a normal `.so` or `.dll` would be loaded, then the `_loader` extension is first loaded. The result returned by `_loader` must be a procedure that accepts a symbol. This procedure will be called with a symbol matching the base part of file-path (without the directory path part of the name and without the filename extension); if `#f` is returned, then `load/use-compiled` ignores `_loader` for file-path and continues as normal. Otherwise, the return value is yet another procedure. When this procedure is applied to no arguments, it should have the same effect as loading file-path.

While a `.zo`, `.so`, or `.dll` file is loaded (or while a thunk returned by `_loader` is invoked), the current `load-relative` directory is set to the directory of the original file-path.

`(load/cd file-path)` is the same as `(load file-path)`, but `load/cd` sets both the current directory and current `load-relative` directory to the directory of file-path before the file's expressions are evaluated.

`(read-eval-print-loop)` starts a new `read`-`eval`-`print` loop using the current input, output, and error ports. When `read-eval-print-loop` starts, it installs a new error escape procedure (see section 8.7) that does not exit the `read`-`eval`-`print` loop. The `read-eval-print-loop` procedure does not return until `eof` is read as an input expression; then it returns void.

The `read-eval-print-loop` procedure is parameterized by the current prompt read handler, the current evaluation handler, and the current print handler; a custom `read`-`eval`-`print` loop can be implemented as in the following example (see also section 9.4.1):

      (parameterize ([current-prompt-read my-read]
                     [current-eval my-eval]
                     [current-print my-print])
        (read-eval-print-loop))

Next: Exiting Up: Support Facilities Previous: Support Facilities