require, load

require, load — load files.

Syntax

require (filename)
load (filename)
require_lisp (filename)
load_lisp (filename)
required_file (filename)
_require_path_ (filename)

		

Arguments

filename

The name of a file, as a string.

Returns

The name of the file, as a string.

Description

The require function loads the named file the first time that it is called. Subsequent calls to require with the same filename will simply be ignored. This provides a means for specifying dependencies for applications containing multiple files.

The load function loads the named file every time it is called. It attempts to open the named file, read expressions and evaluate them one at a time until the end of file is reached. load attempts to find the file by prepending each of the entries in _require_path_ to the filename. If the file is not found, then load appends each of the entries in _load_extensions_ to the path resulting from concatenating _require_path_ and filename. If the file is still not found, nil is returned. If a different grammar has been defined for the loader, then that grammar will be used to read the file.

require_lisp and load_lisp operate similarly to require and load, except they treat any file as a Lisp file. This is helpful when using Lisp libraries with alternate grammars such as Gamma or user-defined grammars.

required_file determines which file would be loaded as the result of a call to require or require_lisp, but does not actually load it. This can be useful in debugging to determine where a particular function or file is coming from.

The pre-defined global variable _require_path_ contains a list of the paths to be searched to find the specified filename. This variable is initialized to ("" "/usr/cogent/lib"), which references the current directory and the standard location for cogent libraries. The list of paths can be augmented with:

_require_path_ = cons ("my_directory_name", _require_path_);

Example

Gamma> require("x/myfile.dat");
"x/myfile.dat"
Gamma> require("x/myfile.dat");
t
Gamma> load("x/myfile.dat");
"x/myfile.dat"
Gamma> required_file("x/myfile.dat");
t
Gamma> require_lisp("myfileli.dat");
nil
Gamma> 
		

See Also

Loading Files