Next: , Previous: REPL, Up: Using Scheme

3.2 Loading Files

To load files of Scheme code, use the procedure load:

— procedure: load filename [environment [syntax-table [purify?]]]

Filename may be a string naming a file, or a list of strings naming multiple files. Environment, if given, is the environment to evaluate the file in; if not given the current REPL environment is used.

Syntax-table is no longer used and if supplied will be ignored.

The optional argument purify? is a boolean that says whether to move the contents of the file into constant space after it is loaded but before it is evaluated. This is performed by calling the procedure purify (see Garbage Collection). If purify? is given and true, this is done; otherwise it is not.

load determines whether the file to be loaded is binary or source code, and performs the appropriate action. By convention, files of source code have a pathname type of "scm", and files of binary SCode have pathname type "bin". Native-code binaries have pathname type "com". (See the description of pathname-type in Pathname Type.)

— variable: load-noisily?

If load-noisily? is set to #t, load will print the value of each expression in the file as it is evaluated. Otherwise, nothing is printed except for the value of the last expression in the file. (Note: the noisy loading feature is implemented for source-code files only.)

All pathnames are interpreted relative to a working directory, which is initialized when Scheme is started. The working directory can be obtained by calling the procedure pwd or modified by calling the procedure cd; see Working Directory. Files may be loaded when Scheme first starts; see the --load command-line option for details.

— procedure: load-option symbol [no-error?]

Loads the option specified by symbol; if already loaded, does nothing. Returns symbol; if there is no such option, an error is signalled. However, if no-error? is specified and true, no error is signalled in this case, and #f is returned.

A number of built-in options are defined:

Support to compress and uncompress files. Undocumented; see the source file runtime/cpress.scm. Used by the runtime system for compression of compiled-code debugging information.
The format procedure. See Format.
Support to access gdbm databases. Undocumented; see the source files runtime/gdbm.scm and microcode/prgdbm.c.
Support to search and do completion on vectors of ordered elements. Undocumented; see the source file runtime/ordvec.scm.
The red-black tree data type. See Red-Black Trees.
Support to search and match strings for regular expressions. See Regular Expressions.
Support to step through the evaluation of Scheme expressions. Undocumented; see the source file runtime/ystep.scm. Used by the Edwin command step-expression.
Support to run other programs as subprocesses of the Scheme process. Undocumented; see the source file runtime/process.scm. Used extensively by Edwin.
Support to run synchronous subprocesses. See Subprocesses.
The weight-balanced tree data type. See Weight-Balanced Trees.

In addition to the built-in options, you may define other options to be loaded by load-options by modifying the file optiondb.scm on the library path. An example file is included with the distribution; normally this file consists of a series of calls to the procedure define-load-option, terminated by the expression

     (further-load-options standard-load-options)
— procedure: define-load-option symbol thunk ...

Each thunk must be a procedure of no arguments. Defines the load option named symbol. When the procedure load-option is called with symbol as an argument, the thunk arguments are executed in order from left to right.