[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.19.1 Loading Scheme file

Function: load file &keyword paths (error-if-not-found #t)
[R5RS+] Loads file, that is, read Scheme expressions in file and evaluates them. An extension ".scm" may be omitted from file.

If file doesn't begin with "/" or "./" or "../", it is searched from the system file search list, stored in a variable *load-path*. Or you can explicitly specify the search path by passing a list of directory names to the keyword argument paths.

On success, load returns #t. If the specified file is not found, an error is signalled unless the keyword argument error-if-not-found is #f, in which case load returns #f.

The current module is preserved; even select-module is called in file, the module in which load is called is restored afterwards.

If you want to load a library file, it's better to use `use' (See section 4.11.2 Defining and selecting modules), or `require' described below. See section 2.6 Compilation, for difference between load and require.

Variable: *load-path*
Keeps a list of directories that are searched by load and require.

If you want to add other directories to the search path, do not modify this variable directly; use add-load-path, described below, instead.

Special Form: add-load-path path &optional (afterp #f)
Adds a path path to the library load path list. If a true value is given to afterp, path is added after the existing paths; otherwise, path is added before the existing paths.

Use this form instead of changing *load-path* directly. This form is a special form and recognized by the compiler; if you change *load-path*, it is in effect at run time, and that may be too late for "use" or "require".

Furthermore, add-load-path looks for the architecture dependent directories under the specified path and if it exists, sets up the internal path list for dynamic loading correctly. Suppose you have your Scheme module in /home/yours/lib, and that requires a dyncamic loadable library. You can put the library under /home/yours/lib/ARCH/, where ARCH is the value (gauche-architecture) returns (See section 6.21.2 Environment Inquiry). Then you can have compiled libraries for multiple platforms and Gauche can still find the right library.

Function: load-from-port port
Reads Scheme expressions from an input port port and evaluates them, until EOF is read.

Function: current-load-port
Function: current-load-history
Function: current-load-next
These procedures allows you to query the current context of loading. They returns the following values when called inside a file being loaded:
current-load-port
Returns the port object from which the file is being read.
current-load-history
Returns a list of pairs of a port and a line number (integer), representing the nesting of loads. Suppose you load `foo.scm', and from its line 7 it loads `bar.scm', and from its line 18 it loads `baz.scm'. If you call current-load-history in the file `baz.scm', you'll get
 
((#<port "foo.scm"> . 7) (#<port "bar.scm"> . 18))
current-load-next
Returns a list of remaining directories to be searched at the time this file is found. Suppose the *load-path* is ("." "../lib" "/home/gauche/lib" "/share/gauche/lib") and you load `foo.scm', which happens to be in `../lib/'. Then, inside `foo.scm', current-load-next returns:
 
("/home/gauche/lib" "/share/gauche/lib")

When called outside of load, these procedures returns #f, () and (), respectively.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated by Ken Dickey on November, 28 2002 using texi2html