Loads the module-file(s) File, if not already loaded and up-to-date imports all exported predicates.
Loads module-file File, if not already loaded and up-to-date imports according to Imports.
Module is already loaded and up-to-date. Imports according to Imports.
Module has not been loaded, or is out-of-date. Loads Module from File and imports according to Imports.
use_module/1accepts a list of file specifications, file extensions optional.
[all], must be ground Either a list of predicate specifications in the Name/Arity form to import into the calling module, or the atom
all, meaning all predicates exported by the module are to be imported.
Loads each specified file except the previously loaded files that have not been changed since last loaded. All files should be module-files; if they are not, warnings are issued. All the exported predicates of the modules are imported into the calling module (or module M if specified).
use_module/2 imports only the predicates in Imports when
loading File. If an attempt is made to import a predicate that
is not public, a warning is issued. If File is not a module-file,
nothing is imported.
use_module/3 allows Module to be
imported into another module without requiring that its source file
(File) be known, as long as the Module already
exists in the system.
use_module/3 is similar to
except that if Module is already in the system, Module, or
predicates from Module, are simply imported into the calling
module, and File is not loaded again. If Module does not
already exist in the system, File is loaded, and
use_module/3 behaves like
use_module/2, except that
Module is unified, after the file has been loaded, with the actual
name of the module in
File. If Module is a variable, File must exist,
and the module name in File is returned.
use_module/1 is similar to
ensure_loaded/1 except that
all files should be module-files; if they are not, warnings are issued.
An attempt to import a predicate may fail or require intervention by the user because a predicate with the same name and arity has already been defined in, or imported into, the loading module (or module M if specified). Details of what happens in the event of such a name clash are given in ref-mod-bas.
After loading the module-file, the source module will attempt to import all the predicates in Imports. Imports must be a list of predicate specifications in Name/Arity form. If the file is not a module-file, nothing is imported. If any of the predicates in Imports are not public predicates, a warning is issued, but the predicates are imported nonetheless. This lack of strictness is for convenience; if you forget to declare a predicate to be public, you can supply the necessary declaration and reload its module, without having to reload the module that has imported the predicate.
use_module/1 may be more convenient at the top level,
use_module/2 is recommended in files because it helps document
the interface between modules by making the list of imported
use_module/2 has also been extended so that the
Imports may be specified as the term
all, in which case it behaves
the same as
use_module/1, importing the entire module into the caller.
use_module/[1,2] could be defined as:
use_module(Files) :- load_files(Files, [if(changed)]). use_module(File, Imports) :- load_files([File], [if(changed),imports(Imports)]).
use_module/3 can be used to access the (primary) module name of a module-file:
| ?- use_module(Module, library(clpfd), all). % loading /src/sicstus/matsc/sicstus4/Utils/x86-linux-glibc2.3/bin/sp-4.1.0/sicstus-4.1.0/library/clpfd.po... [...] % loaded /src/sicstus/matsc/sicstus4/Utils/x86-linux-glibc2.3/bin/sp-4.1.0/sicstus-4.1.0/library/clpfd.po in module clpfd, 830 msec 496796 bytes Module = clpfd ? yes