11.3.75 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. See ref-lps-flg for more info on the Prolog flag host_type. The environment variables 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 run-time.

     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').

Examples

     | ?- assert(user:file_search_path(home, '/usr/joe_bob')).
     
     yes
     | ?- assert(user:file_search_path(review, home('movie/review'))).
     
     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.


Send feedback on this subject.