Previous Up Next

3.7  How do I use ECLiPSe libraries in my programs?

A number of files containing library predicates are supplied with the ECLiPSe system. These predicates provide utility functions for general use. They are usually installed in an ECLiPSe library directory (or directories). These predicates are either loaded automatically by ECLiPSe or may be loaded “by hand”.

During the execution of an ECLiPSe program, the system may dynamically load files containing library predicates. When this happens, the user is informed by a compilation or loading message. It is possible to explicitly force this loading to occur by use of the lib/1 or use_module/1 predicates. e.g., to load the library called lists, use one of the following goals:

lib(lists)
use_module(library(lists))

This will load the library file unless it has been already loaded. In particular, a program can ensure that a given library is loaded when it is compiled, by including an appropriate directive in the source, e.g., :- lib(lists).

Library files are found by searching the library path and by appending a suffix to the library name. The search path used when loading libraries is specified by the global flag library_path using the get_flag/2 and set_flag/2 predicates. This flag contains a list of strings containing the pathnames of the directories to be searched when loading a library file. User libraries may be be added to the system simply by copying the desired file into the ECLiPSe library directory. Alternatively the library_path flag may be updated to point at a number of user specific directories. The following example illustrates how a directive may be added to a file to add a user-defined library in front of any existing system libraries.

?- get_flag(library_path,Path),
   set_flag(library_path, ["/home/myuser/mylibs" | Path]).

The UNIX environment variable ECLIPSELIBRARYPATH may also be used to specify the initial setting of the library path. The syntax is similar to the syntax of the UNIX PATH variable, i.e., a list of directory names separated by colons. The directories will be prepended to the standard library path in the given order.


Previous Up Next