file_search_path/2 extendable


:- multifile file_search_path/2.

file_search_path(*PathAlias, *DirSpec)

Defines a symbolic name for a directory or a path. Used by predicates taking file_spec as input argument.


PathAlias atom
A string that represents the path given by DirSpec.
DirSpec file_spec
Either a string giving the path to a file or directory, or PathAlias(DirSpec), where PathAlias is defined by another file_search_path/2 rule.


file_search_path/2 is a dynamic, multifile predicate. It resides in module user.

The file_search_path mechanism provides an extensible way of specifying a sequence of directories to search to locate a file. For instance, if a filename is given as a structure term, library(basics). The principle functor of the term, library, is taken to be another file_search_path/2 definition of the form

     file_search_path(library, LibPath)

and file basics is assumed to be relative to the path given by LibPath. LibPath may also be another structure term, in which case another file_search_path/2 fact gives its definition. The search continues until the path is resolved to an atom.

There may also be several definitions for the same PathAlias. Certain predicates, such as load_files/[1,2] and absolute_file_name/[2,3], search all these definitions until the path resolves to an existing file.

There are several system defined search paths, such as quintus, runtime, library, system, helpsys. These are initialized at system startup, and used by some of the system predicates, but they may be redefined by the user. Furthermore, the user may create extra file_search_paths to define certain paths, and these may be used exactly as the predefined system paths. See ref-fdi for more detail.


     | ?- assert(file_search_path(home, '/usr/joe_bob')).
     | ?- assert(file_search_path(review, home('movie/review'))).
     | ?- compile(review(blob)).
     % compiling /usr/joe_bob/movie/review/

See Also

absolute_file_name/[2,3], assert/[1,2], dynamic/1, library_directory/1, listing/1, load_files/[1,2], ref-fdi.