load_files/[1,2]

Synopsis

load_files(+Files)

load_files(+Files, +Options)

[+File|+Files]

[]

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

Arguments


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:

if(X)

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

when(X)

X=run_time
(default) The file does not define any predicates that will be called during compilation of other files.
X=compile_time
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.
X=both
the file defines some predicates that will be needed during compilation and some that will be needed during execution.

load_type(X)

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

must_be_module(X)

X=true
the files are required to be module-files
X=false
(default) the files need not be module-files

imports(X)

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

all_dynamic(X)

X=true
load all predicates as dynamic
X=false
(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.

silent(X)

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

Description

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] :-
             load_files([File|Files]).
     compile(Files) :-
             load_files(Files, [load_type(compile)]).
     consult(Files) :-     /*consult equivalent to
                             compile now*/
             compile(Files).
     ensure_loaded(Files) :-
             load_files(Files, [if(changed)]).
     use_module(Files) :-
             load_files(Files, [if(changed),
                          must_be_module(true)]).
     use_module(File, Imports) :-
             load_files(File,  [if(changed),
                          must_be_module(true),
                          imports(Imports)]).
     

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.

Exceptions


instantiation_error
M, Files, or Options is not ground.
type_error
In M, in Files, or in Options.
domain_error
Illegal option in Options.
existence_error
A specified file does not exist. If the fileerrors flag is off, the predicate fails instead of raising this exception.
permission_error
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