Next: , Previous: r6rs libraries import, Up: r6rs libraries


77.4.5 Finding libraries on the system

The bindings documented in this section are exported by the (nausicaa parser-tools r6rs libraries) library.

Search path
— Parameter: library-search-path-environment-variable

Holds a string representing the system environment variable holding the search path for libraries; it is initialised to ‘R6RS_LIBPATH’. The search path is meant to be a colon–separated list of absolute directory pathnames.

— Function: library-search-path

Read the value of the library-search-path-environment-variable parameter and return a list of <pathname> records representing the directory pathnames in the search path, see pathnames abstract class.

— Parameter: library-search-path-function

Hold a thunk which, when evaluated, returns a list of strings representing the directories pathnames in the search path; it is initialised to library-search-path.

Composing library file pathnames
— Function: library-reference->file-pathname (ref <library-reference>) file-extension

Given a library reference record and a file extension string (leading dot included): build and return a <relative-pathname> record representing the file pathname.

This function joins the identifiers in the library names with a slash separator; it ignores the version specification.

— Parameter: library-reference->file-pathname-function

Hold a function which, when applied to a <library-reference> record and a string representing a file extension (leading dot included), returns a <relative-pathname> record representing the file pathname; it is initialised to library-reference->file-pathname.

Finding pathnames
— Constant: library-file-extensions

A list of strings representing extensions for library files to be searched for in the given order; its value is:

.mosh.sls’ ‘.sls
For Mosh Scheme.
.mzscheme.sls’ ‘.sls
For Racket with R6RS language.
.chezscheme.sls’ ‘.sls
For Petite Chez Scheme.
.vicare.sls’ ‘.sls
For Vicare Scheme.
.ypsilon.sls’ ‘.sls
For Ypsilon Scheme.

— Function: scan-library-search-path (reference <library-reference>)

Given the reference record, make use of the thunk in library-search-path-function and the extensions in library-file-extensions to scan the file systems in search of compliant libraries. Return a, possibly null, list of <absolute-pathname> records representing the file pathnames.

This function searches for all the files whose pathname is prefixed with a directory in the search path and suffixed with a relative pathname built by joining the identifiers in the library reference with a separator; finally the extensions are tried in turn. This function ignores library version specifications in pathnames.

— Parameter: scan-library-search-path-function

Holds a function which, when applied to a <library-reference> record, scans the file systems and returns a list of file pathnames matching the reference. It is initialised to scan-library-search-path.

Loading libraries
— Function: load-libraries-from-files (R <library-reference>)

Make use of the function in scan-library-search-path-function to find, on the system, libraries matching the record R and return a list of <library> records representing them. If loading a library file fails: the error is ignored and that pathname skipped.

— Parameter: load-library-function

Hold a function used to inspect the system in search for libraries whose name match a given library reference. It is initialised with load-libraries-from-files.

— Function: load-library (R <library-reference>)
— Function: load-library (R <library-reference>) (S <library-store>)

Given a library reference record R, inspect the system and load all the libraries having name matching the reference; return a possibly null list of <library> records sorted from higher version to lower version number.

Make use of load-library-function to inspect the system.

When S is used, and it is not #f, this function first searches the store for already loaded libraries: if at least one is found, the system is not inspected; if none are found, the system is inspected and the result saved in the store.