This section contains a summary of the relevant predicates. For a more precise description, see Read In.
To consult a program, issue the query:
| ?- consult(Files).
where Files is either a filename or a list of filenames, instructs the processor to read in the program that is in the files. For example:
| ?- consult([dbase,'extras.pl',user]).
When a directive is read it is immediately executed. Any
predicate defined in the files erases any clauses for that
predicate already present. If the old clauses were
loaded from a different file than the present one, the user will
be queried first whether (s)he really wants the new definition.
However, if a multifile
declaration (see Declarations)
is read and the corresponding predicate exists and has previously
been declared as multifile
, new clauses will be added to
the predicate, rather than replacing the old clauses. If
clauses for some predicate appear in more than one file, the
later set will effectively overwrite the earlier set. The division of
the program into separate files does not imply any module
structure—any predicate can call any other (see Module Intro).
consult/1
, used in conjunction with save_program/[1,2]
and
restore/1
, makes it possible to amend a program without
having to restart from scratch and consult all the files that make
up the program. The consulted file is normally a temporary
“patch” file containing only the amended predicate(s). Note
that it is possible to call consult(user)
and then enter a patch
directly on the terminal (ending with ^D). This is only
recommended for small, tentative patches.
| ?- [File|Files].
This is a shorthand way of consulting a list of files. (The case where there is just one filename in the list was described earlier (see Reading In).
To compile a program in-core, use the built-in predicate:
| ?- compile(Files).
where Files is specified just as for consult/1
.
The effect of compile/1
is very much like that of
consult/1
, except all new predicates will be stored in
compiled rather than consulted form. However,
predicates declared as dynamic (see below) will be stored in
consulted form, even though compile/1
is used.
Programs can be compiled into an intermediate representation known as `.ql' (for Quick Load file). As of SICStus Prolog 3.8, this feature is obsolescent with the introduction of partial saved-states (`.po' files; see Saving), which can be handled much more efficiently.
To compile a program into a `.ql' file, use the built-in predicate:
| ?- fcompile(Files).
where Files is specified just as for consult/1
. For each
filename in the list, the compiler will append the suffix
`.pl' to it and try to locate a source file with that name and
compile it to a `.ql' file. The filename is formed by
appending the suffix `.ql' to the specified name. The internal
state of SICStus Prolog is not changed as result of the
compilation. See Considerations.
To load a program from a set of source or object files, use
the built-in predicates load_files/[1,2]
(the latter is
controlled by an options list):
| ?- load_files(Files).
where Files is either a single filename or a list of filenames, optionally with `.pl' or `.po' or `.ql' extensions. This predicate takes the following action for each File in the list of filenames:
user
, compile(user)
or [user]
is
performed;
load_files/1
was called
from a directive of a file being consulted.
Finally, to ensure that some files have been loaded, use the built-in predicate:
| ?- ensure_loaded(Files).
Same as load_files(Files)
, except if the file to be loaded
has already been loaded and has not been modified since that time,
in which case the file is not loaded again. If a source file has
been modified, ensure_loaded/1
does not cause any object
file to become recompiled.