11.3.113 load_files/[1,2]



load_files(+Files, +Options)


Loads the specified Prolog source and/or object file(s) into memory. Subsumes all other load predicates.


file_spec or list of file_spec, must be ground

A file specification or a list of file specifications; extensions optional.

list of term, must be ground

A list of zero or more options of the form:

true (the default) to always load, or changed to load only if the file has not yet been loaded or if it has been modified since it was last loaded. A non-module-file is not considered to have been previously loaded if it was loaded into a different module. The file user is never considered to have been previously loaded.
always (the default) to always load, or compile_time to load only if the goal is not in the scope of another load_files/[1,2] directive occurring in a PO file.

The latter is intended for use when the file only defines predicates that are needed for proper term or goal expansion during compilation of other files.

source to load source files only, object to load object (PO) files only, or latest (the default) to load any type of file, whichever is newest. If the file is user, source is forced.
all (the default) to import all exported predicates if the file is a module-file, or a list of predicates to import.
compile to translate into compiled code, consult to translate into static, interpreted code, or assert_all to translate into dynamic, interpreted code.

The default is the compilation mode of any ancestor load_files/[1,2] goal, or compile otherwise. Note that Mode has no effect when a PO file is loaded, and that it is recommended to use assert_all in conjunction with load_type(source), to ensure that the source file will be loaded even in the presence of a PO file.

In addition the open/4 options encoding/1, encoding_signature/1 and eol/1 can be specfied. These will be used if the Prolog code is loaded from a source file. See mpg-ref-open, for details.


load_files/[1,2] reads Prolog clauses, in source or precompiled form, and adds them to the Prolog database, after first deleting any previous versions of the predicates they define. Clauses for a single predicate must all be in the same file unless that predicate is declared to be multifile.

If a source file contains directives, that is, terms with principal functor :-/1 or ?-/1, then these are executed as they are encountered. Initialization goals specified with initialization/1 are executed after the load.

A non-module source file can be loaded into any module by load_files/[1,2], but the module of the predicates in a precompiled file is fixed at the time it is created.


Files or Options is not ground.
In Files or Options.
Illegal option in Options.
A specified file does not exist. If the fileerrors flag is off, the predicate fails instead of raising this exception.
A specified file is protected. If the fileerrors flag is off, the predicate fails instead of raising this exception.

See Also


Send feedback on this subject.