11.3.78 file_search_path/2 [hook]

Synopsis

:- multifile user:file_search_path/2.

user:file_search_path(+PathAlias, +DirSpec)

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

Arguments

PathAlias
atom

An atom that represents the path given by DirSpec.

DirSpec
file_spec

Either an atom giving the path to a file or directory, or PathAlias(DirSpec), where PathAlias is defined by another file_search_path/2 rule.

Description

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 predefined search paths, such as application, runtime, library, system. These are tried before the user-defined ones.

The predicate is undefined at startup, but behaves as if it were a multifile predicate with the following clauses. The system properties SP_APP_DIR and SP_RT_DIR expand respectively to the absolute path of the directory that contains the executable and the directory that contains the SICStus runtime (see System Properties and Environment Variables), SP_TEMP_DIR expand to a directory suitable for storing temporary files.

     file_search_path(library, Path) :-
             library_directory(Path).
     file_search_path(system, Platform) :-
             prolog_flag(host_type, Platform).
     file_search_path(application, '$SP_APP_DIR').
     file_search_path(runtime, '$SP_RT_DIR').
     file_search_path(temp, '$SP_TEMP_DIR').
     file_search_path(path, Dir) :-
             ... backtracks through the $PATH environment variable ...

Examples

     | ?- [user].
     % compiling user...
     | :- multifile user:file_search_path/2.
     | user:file_search_path(home, '/usr/joe_bob').
     | user:file_search_path(review, home('movie/review')).
     | end_of_file.
     % compiled user in module user, 0 msec 768 bytes
     yes
     | ?- compile(review(blob)).
     % compiling /usr/joe_bob/movie/review/blob.pl

See Also

absolute_file_name/[2,3], library_directory/1, load_files/[1,2], ref-fdi, ref-lps-flg, System Properties and Environment Variables.


Send feedback on this subject.