Commands in Files

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.


  1. The :- symbol is placed at the beginning of the line just as it appears in the example above.
  2. When a file being compiled contains a command to compile another file, a relative filename in that command is interpreted with reference to the directory that contains the first file. For example, if the file /usr/fred/ contains the following commands
              :- compile('../whatsit').
              :- compile('').

    then the files to be compiled would be /usr/ (or /usr/whatsit) and /usr/fred/

    For example, you can have a file called containing

              :- [file1, file2, file3].

    and provided that you keep all of these files in the same directory as, you can compile them all, no matter what your current working directory is, by giving compile/1 a file specification for