Linguistics 482 - Computational Linguistics Prolog Notes A. C. Brett
Department of Linguistics
University of Victoria
Clearihue C139
Last updated: 8 November 2001

System Predicates

System predicates are predicates that are included in the Prolog interpreter, the Listener, to perform frequently used and useful tasks, or operations that a Prolog program cannot undertake.

Some system predicates clearly serve as instructions to the Listener. Predicates in this category include consult/1, that identifies a Prolog program to the Listener, and listing/0 and listing/1, that show the clauses in a program. Some system predicates can appear as, or be included in, the clauses of a Prolog program. These system predicates can also be viewed as instructions to the Listener that, within the context of a Prolog program, cause the Listener to perform operations that the Prolog program itself cannot undertake.

Those system predicates that function as instructions often have the appearance of commands, consisting of imperative mood verb forms such as "reconsult", "write", or "abolish". Although the notion of a command would seem to be incompatible with the descriptive nature of the Prolog language, the form taken by these instruction-like predicates is nonetheless consistent with Prolog syntax and morphology in that they are represented as goal structures. These goals may be typed as queries or claims, or included in the clauses of a Prolog program.

An alphabetical list of the system predicates, with a brief note on each, is available in the Predicate Quick Reference item of the Amzi! Prolog help system described in the Getting Listener Help section of these notes. Several frequently used system predicates are described below for illustrative purposes.

Listing the Clauses in a Program or Predicate

It is sometimes helpful to have the Listener list all the clauses in a Prolog program that has been consulted. To obtain this listing, type the following goal:
at the Listener "?-" prompt. If you want to see just the clauses that comprise predicates with a particular name, then you can use the listing/1 predicate, rather than the listing/0 predicate illustrated above. For example, if you want a list of all the clauses in predicates with the name lex, then type the following:
If, however, you want a list of only those clauses in, for example, the lex/3 predicate, then you can type either
   listing(lex, 3).
where the latter makes use of the listing/2 predicate.

Displaying Text and Intermediate Results

It can be useful, and sometimes necessary, to have the Listener display information beyond the "yes" or "no" response to a query or claim. The write/1 predicate can be used to cause the Listener to display additional information. The nl/0, "new line" predicate is often employed in conjunction with the write/1 predicate so that terms in the argument of successive references to write/1 are displayed, when it is appropriate, on separate lines.

For example, suppose your Prolog program includes the following clauses:

   % S --> NP VP
     s(V, W, X, Y, Z) :- np(V, W), vp(X, Y, Z).

   % NP --> DET N
     np(X, Y) :- det(X), n(Y).
and because there seems to be a problem with the program, you want to follow the process of proving the np(V, W) goal. You might therefore include the write/1 and nl/0 predicates as goals in the bodies of the two rules as shown in the following lines:
   % S --> NP VP
     s(V, W, X, Y, Z) :- nl, write($s/5 predicate, np(V, W) goal:$), 
                         np(V, W), vp(X, Y, Z).

   % NP --> DET N
     np(X, Y) :- nl, write($DET?: $), write(X), det(X),
                     write($  N?: $), write(Y), n(Y).
The string in the argument of the write/1 predicate in the body of the s/5 rule will be displayed before the np(V, W) goal is proved so that it will appear as a header or title for whatever lines are displayed during the proof of the np(V, W) goal. The reference to the nl/0 predicate will cause the string to be displayed beginning on a new line, rather than being appended to whatever over information might have been displayed previously.

When the np(V, W) goal is proved, the string consisting of the text DET?: will be displayed, beginning on a new line, followed by the term that has been instantiated on the variable X. If the goal det(X) can be proved, then the text N?: will be displayed, followed by the term instantiated on Y. Of course, if the word instantiated on X is not a determiner, it will still be displayed, but the goal det(X) will not be proved, and hence, the text N?: will not be displayed. This result might be sufficient for you to discover the source of the problem with your program. If not, then additional references to the write/1 predicate, with appropriate arguments, might be required elsewhere in your program.

Abolishing Predicates

Although you may have deliberately eliminated a predicate while correcting or modifying a program, the Listener will not necessarily be "aware" of this change to your program when you reconsult it. To get rid of the old predicate, as far as the Listener is concerned, you can use the abolish system predicate.

For example, if you originally had an np/1 predicate in your program, and you change it to an np/2 predicate in your modified program, you can eliminate the np/1 predicate by typing

   abolish(np, 1).
at the "?-" Listener prompt.

Linguistics 482 Prolog Introductory Notes Top of Page