4.5.1 The File Search Path Mechanism

As a convenience for the developer and as a means for extended portability of the final application, SICStus Prolog provides a flexible mechanism to localize the definitions of the system dependent parts of the file and directory structure a program relies on, in such a way that the application can be moved to a different directory hierarchy or to a completely new file system, with a minimum of effort.

This mechanism, which can be seen as a generalization of the user:library_directory/1 scheme available in previous releases, presents two main features:

  1. An easy way to create aliases for frequently used directories, thus localizing to one single place in the program the physical directory name, which typically depends on the file system and directory structure.
  2. A possibility to associate more than one directory specification with each alias, thus giving the developer full freedom in sub-dividing libraries, and other collections of programs, as it best suits the structure of the external file system, without making the process of accessing files in the libraries any more complicated. In this case, the alias can be said to represent a file search path, not only a single directory.

The directory aliasing mechanism, together with the additional file search capabilities of absolute_file_name/3, can effectively serve as an intermediate layer between the external world and a portable program. For instance, the developer can hide the directory representation by defining directory aliases, and he can automatically get a proper file extension added, dependent on the type of file he wants to access, by using the appropriate options to absolute_file_name/3.

A number of directory aliases and file search paths, are predefined in the SICStus Prolog system. The most important of those is the library file search path, giving the user instant access to the SICStus library, consisting of several sub-directories and extensive supported programs and tools.

Specifying a library file, using the alias, is possible simply by replacing the explicit file (and directory) specification with the following term:


The name of the file search path, in this case library, is the main functor of the term, and indicates that file is to be found in one of the library directories.

The association between the alias library (the name of the search path) and the library directories (the definitions of the search path), is extended by Prolog facts, user:library_directory/1, which are searched in sequence to locate the file. Each of these facts specifies a directory where to search for file, whenever a file specification of the form library(file) is encountered.

The library mechanism discussed above, which can be extended with new directories associated with the alias library, has become subsumed by a more general aliasing mechanism, in which arbitrary names can be used as aliases for directories. The general mechanism also gives the possibility of defining path aliases in terms of already defined aliases.

In addition to library, the following aliases are predefined in SICStus Prolog: runtime, system, application, temp, and path. The interpretation of the predefined aliases are explained below.

Send feedback on this subject.