A Prolog source file can contain commands as well as clauses. If you have a program that is spread across many files, it may be useful to create a file containing commands to load each of those files. For example, such a file could look like this:
:- compile(file1). :- compile(file2). :- compile(file3).
When this master-file is compiled, the % compiling File...
and
% File compiled
messages for file1, file2 and file3 will be indented
by one character. If they in turn cause other files to be loaded, the
messages for those files will be indented two characters, and so on.
Notes:
:-
symbol is placed at the beginning of the line just as
it appears in the example above.
/usr/fred/test.pl
contains the following commands
:- compile('../whatsit'). :- compile('xyz.pl').
then the files to be compiled would be /usr/whatsit.pl
(or /usr/whatsit
) and
/usr/fred/xyz.pl
.
For example, you can have a file called mainfile.pl
containing
:- [file1, file2, file3].
and provided that you keep all of these files in the same directory as
mainfile.pl
, you can compile them all, no matter what your current
working directory is, by giving compile/1
a file specification
for mainfile.pl
.