Next: , Previous: , Up: The Library System   [Contents][Index]

1.2 Require

SLIB creates and maintains a catalog mapping features to locations of files introducing procedures and syntax denoted by those features.

Variable: *catalog*

Is an association list of features (symbols) and pathnames which will supply those features. The pathname can be either a string or a pair. If pathname is a pair then the first element should be a macro feature symbol, source, compiled, or one of the other cases described in Library Catalogs. The cdr of the pathname should be either a string or a list.

At the beginning of each section of this manual, there is a line like (require 'feature). The Scheme files comprising SLIB are cataloged so that these feature names map to the corresponding files.

SLIB provides a form, require, which loads the files providing the requested feature.

Procedure: require feature
  • If (provided? feature) is true, then require just returns.
  • Otherwise, if feature is found in the catalog, then the corresponding files will be loaded and (provided? feature) will henceforth return #t. That feature is thereafter provided.
  • Otherwise (feature not found in the catalog), an error is signaled.

There is a related form require-if, used primarily for enabling compilers to statically include modules which would be dynamically loaded by interpreters.

Procedure: require-if condition feature

Requires feature if condition is true.

The random module uses require-if to flag object->string as a (dynamic) required module.

(require 'byte)
(require 'logical)
(require-if 'compiling 'object->string)

The batch module uses require-if to flag posix-time as a module to load if the implementation supports large precision exact integers.

(require-if '(and bignum compiling) 'posix-time)

The catalog can also be queried using slib:in-catalog?.

Function: slib:in-catalog? feature

Returns a CDR of the catalog entry if one was found for the symbol feature in the alist *catalog* (and transitively through any symbol aliases encountered). Otherwise, returns #f. The format of catalog entries is explained in Library Catalogs.


Next: , Previous: , Up: The Library System   [Contents][Index]