Loading a File into Prolog

If you have created a Prolog program and stored it in a file called myfile.pl, you can load that file into Prolog by typing the following:

     | ?- compile(myfile).
     

This goal has the effect of compiling your file into the Prolog database. A message is displayed showing the absolute filename:

     % compiling /ufs/joe/myfile.pl...
     

When Prolog finishes compiling a file, it displays the name of the file that was compiled, the amount of time it took to compile the file, and the number of bytes required to store the compiled file in memory. If an earlier version of the file or another file of the same name has been previously compiled during this Prolog session, this last number represents the number of additional bytes required to recompile the file, and may be zero (or even negative, if the new version takes up less space than the old).

     % myfile.pl compiled 2.354 sec 2346 bytes
     | ?-
     

As shown above, the main Prolog prompt reappears after the system finishes compiling a file. At this point, you can begin running or testing by typing calls to the predicates that the file defines.

The predicate compile/1 also accepts a list of files as an argument. For example, to compile three files called file1.pl, file2.pl, and file3.pl, type

     | ?- compile([file1,file2,file3]).