load_files(+Files, +Options)



Load the specified Prolog source and/or QOF files into memory. Subsumes all other load predicates.


Files file_spec or list of file_spec [MOD]
a file specification or a list of file specifications; a .pl or .qof extension may be omitted in a file specification.
Options list
a list of zero or more options of the form:


(default) always load
load file if it is not already loaded or if it has been changed since it was last loaded


(default) The file does not define any predicates that will be called during compilation of other files.
the file only defines predicates that wil be called during compilation of other files; it does not define any predicates that will be called when the application is running.
the file defines some predicates that will be needed during compilation and some that will be needed during execution.


compile Prolog source code
load QOF code
(default) load QOF or compile source, whichever is newer. The latest option is effective only if Files are sepcified without extensions.


the files are required to be module-files
(default) the files need not be module-files


(default) if the file is a module-file, all exported predicates are imported
list of predicates to be imported
Note that if the option imports is present, the option must_be_module(true) is enforced.


load all predicates as dynamic
(default) load predicates as static unless they are declared dynamic
Note that the all_dynamic option has no effect when a QOF file is loaded. Thus it is not normally useful to use all_dynamic(true) in conjunction with load_type(latest), since the file will be loaded in dynamic mode only if the source file is more recent than the QOF file.


loading information is printed as silent messages (see ref-msg for details).
(default) loading information is printed as informational message.


load_files/2 is the most general predicate for loading Prolog files. Special cases of it are provided by the following predicates:

     load_files(Files) :-
             load_files(Files, []).
     [File|Files] :-
     compile(Files) :-
             load_files(Files, [load_type(compile)]).
     consult(Files) :-     /*consult equivalent to
                             compile now*/
     ensure_loaded(Files) :-
             load_files(Files, [if(changed)]).
     use_module(Files) :-
             load_files(Files, [if(changed),
     use_module(File, Imports) :-
             load_files(File,  [if(changed),

load_files/[1,2] reads Prolog clauses, in source or in compiled (QOF) 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 the file contains directives, that is, terms with principal functor :-/1 or ?-/1, then these are executed as they are encountered.

Clauses and directives can be transformed as they are read from source files (not from QOF), by providing a definition for term_expansion/2. This is true in both the development system and QPC, but in order for this to work properly in QPC, your definition of term_expansion/2 (and everything it calls) must be loaded into QPC. This is accomplished with the when option to load_files/2, or the -i option to QPC.

A non-module source file can be loaded into any module by load_files/[2,3], but the module of the predicates in a QOF-file is fixed at the time it is created (by QPC, save_predicates/2 or save_program/[1,2]). It is thus not possible to qof save a predicate from say module foo, and reloaded it into module bar, or QPC the non-module-file f1.pl into f1.qof, and then load f1.qof into module mod (QPC assumes module user when non-module files are compiled separately). To avoid mistakes, load_files/[1,2] loads the corresponding source file, if such exists, whenever a non-module-file is loaded into module other than user. If no corresponding source file exists, the QOF file is loaded; care should be taken in this case.

Initialization goals specified with initialization/1 are executed after the load.

When load_files/[1,2] is called from an embedded command in a file being compiled by QPC, the load_type and if options are ignored. The specfied files are compiled from source to QOF, if the source is newer than the corresponding QOF file. If the option when(compile_time) is given, the file is instead compiled into QPC memory, and no QOF is generated (see above).

When load_files/[1,2] is called in a runtime system, the all_dynamic option will be automatically set to true because the compiler is not available in runtime systems. This means that the loaded code will run slower.


M, Files, or Options is not ground.
In M, in Files, or in 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

compile/1, consult/1, dynamic/1, ensure_loaded/1, fileerrors/0, multifile/1, no_style_check/1, nofileerrors/0, prolog_load_context/2, source_file/[1,2], style_check/1, term_expansion/2, use_module/[1,2,3], initialization/1, volatile/1. ref-lod