How To Load Files

The Bracket Notation

The bracket notation is the simplest way to load files. For example,
?- [''].
Loads the file "". Note the use of single quotes round the filename. These are necessary because it contains the character "." which has a special meaning in Prolog.

Multiple files can be loaded as follows:

?- ['',',']. 
would load (effectively reconsult) all three files into memory. On some Prolog systems (including SWI-Prolog) the file extension ".pl" is assumed so that the last example can be abbreviated by
?- [file1,file2,file3]. 
Note that if the filename consists only of alphanumeric characters, there is no need for the single quote.

Consult and Reconsult

The standard Prolog predicates for loading programs are 'consult', 'reconsult', and the bracket loader notation '[ ...]'. For example, the goal
?- consult(''). 
opens the file and loads the clauses in that file into memory. If this program was not correct, and one edited the file using the goal, then upon returning from the editor (and assuming that the new version of the file was resaved using the same file name), one could use the goal
 ? reconsult('').  
to reload the clauses into memory, automatically replacing the old definitions. If one had here used 'consult' rather than 'reconsult' the old (and possibly incorrect) clauses would have remained in memory along with the new clauses (depends upon the Prolog system, actually).

If several files have been loaded into memory, and one needs to be reloaded, use 'reconsult'. If the reloaded file defines predicates which are not defined in the remaining files then the reload will not disturb the clauses that were originally loaded from the other files.

Editing Files

For SWI Prolog on the Sun Workstations, it is perhaps easiest to use the emacs editor or the Solaris text editor tool to edit programs. For the Solaris text editor tool, edit the Prolog program in a separate text editor window and save the program when the desired changes have been made; then reconsult the edited program as above. The emacs editor is capable of executing the Prolog goals for the edited program from the editor environment. See the emacs documentation to learn how to use this program editor environment.

Direct Input of Clauses

To load clauses supplied interactively by the user, use any of the following goals
?-consult(user). or
?- reconsult(user).
In the last case, the user types in clauses interactively, using period '.' at the end of clauses, and ^Z to end input.

This page is a slightly modified version of that appearing in the Prolog Tutorial, by J.R. Fisher.
Mike Rosner (
Last modified: Mon Mar 10 16:13:06 MET