[previous] [up] [next]     [contents] [index]
Next: Exiting Up: Support Facilities Previous: Support Facilities

Eval and Load

(eval e) evaluates the S-expression e in the current namespace.[footnote] (See section 9.3 and section 9.4.1.6 for more information about namespaces.)

(load filename) evaluates each expression in the specified file using eval.[footnote] 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 filename is a relative pathname, then it is resolved to an absolute pathname using the current directory. Before the first expression of filename 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 filename; after the last expression in filename is evaluated (or when the load is aborted), the load-relative directory is restored to its pre-load value.

(load-relative filename) is like load, but when filename 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 filename) is like load-relative, but load/use-compiled also checks for .zo files (usually produced with compile-file; see section 15.2.4) and .so (Unix and MacOS) or .dll (Windows) files. The check for a compiled file occurs whenever filename 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 filename. 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 filename. 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 pasrt of filename (without the directory path part of the name and without the filename extension); if #f is returned, then load/use-compiled ignores _loader for filename 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 filename.

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 filename.

(load/cd filename) is the same as (load filename), but load/cd sets both the current directory and current load-relative directory to the directory of filename 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.6) 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))


[previous] [up] [next]     [contents] [index]
Next: Exiting Up: Support Facilities Previous: Support Facilities

PLT