Next: , Previous: , Up: Run Intro   [Contents][Index]


3.2 Reading in Programs

A program is made up of a sequence of clauses and directives. The clauses of a predicate do not have to be immediately consecutive, but remember that their relative order may be important (see ref-sem).

To input a program from a file file, issue a query of the form:

| ?- compile(file).

or the equivalent but shorter form

| ?- [file].

This instructs the system to read in (compile) the program. Note that it may be necessary to enclose the filename file in single quotes to make it a legal Prolog atom; e.g.:

| ?- compile('myfile.pl').

| ?- ['/usr/prolog/somefile'].

The specified file is then read in. Clauses in the file are stored so that they can later be run, while any directives are obeyed as they are encountered. When the end of the file is found, the system displays on the standard error stream the time spent. This indicates the completion of the query.

Predicates that expect the name of a Prolog source file, or more generally a file specification, use the facilities described in ref-fdi to resolve the file name. File extensions are optional. There is also support for libraries.

This query can also take a list of filenames, such as:

| ?- [myprog,extras,tests].

or

| ?- compile([myprog,extras,tests]).

In this case all three files would be loaded. The clauses for all the predicates in the loaded files will replace any existing clauses for those predicates, i.e. any such previously existing clauses in the database will be deleted.



Send feedback on this subject.