Filename Defaults

Some of the predicates that take file specification arguments not only can search for a file among the directories defined by file_search_path/2 facts (if a path alias is used), but also can help the user in finding the correct file by adding appropriate extensions and/or looking for the most recent file by comparing modification times.

load_files/[1,2] (and the predicates defined in terms of load_files/2), uses the following algorithm to find the most appropriate file to load:

  1. if the file specification is of the form PathAlias(FileName), retrieve the first directory in the search path associated with PathAlias and apply the algorithm below in that directory (for instance, if library(strings) are given, look in the first library directory, with FileName set to strings):
  2. if FileName exists, load it.
  3. if exists, but not FileName.qof, load
  4. if FileName.qof exists, but not, load FileName.qof
  5. if both and FileName.qof exist, load the one that was most recently modified.
  6. if the file specification contained a path alias, retrieve the next directory in the path and retry from (2).

For example,

     | ?- [user].
     | :- multifile file_search_path/2.
     | :- dynamic file_search_path/2.
     | file_search_path(home, '/usr').
     | file_search_path(home, '/usr/prolog').
     | end_of_file.        % (or <^D>)
     % user compiled in module user, 0.034 sec 284 bytes

In this case the directory /usr is searched first and /usr/prolog second. Therefore, if the file exists in both of these directories, the following query will compile in the directory /usr (on the condition that foo.qof does not exist).

      | ?- compile(library(foo)).