.de np
.ti -8
.sp
..
?he'PROLOG''Page %'
?fo 'Claude Sammut'- % -'17 July, 1980'
.mh
PROLOG INTERPRETER
.br
------------------
.hm
.pg
This is a brief guide for the Prolog interpeter
which runs on the POP11 system.
It is not intended as an introduction to the Prolog langauge.
Warren, [Software - Practice and Experience, Vol. 10, 97-125 (1980)]
provides a good tutorial in the use of Prolog.
.pg
Prolog lives in the user library and can be loaded by typing,
.ce
: lib prolog;
Several built-in predicates will be loaded automatically.
To add your own programs type,
.ce
: add;
The prompt character will change to '*' while Prolog clauses
are being input.
Whatever is typed will be inserted directly into the database,
no execution or syntax checking takes place.
To return to POP11 type ^d.
.pg
The syntax of this version of Prolog is prefix notation like LISP.
For example, in DECsystem-10 Prolog, append may be written as follows:
.nf
	append(nil, X, X) :- !.
	append(cons(A, B), X, cons(A, B1)) :- !, append(B, X, B1).
.fi
In POP-Prolog the translates to:
.nf
	[[append nil X X] !]
	[[append [cons A B] X [cons A B1]] ! [append B X B1]]
.fi
.pg
A clause is represented by a list of terms.
The first term is the clause header.
A term may itself be a list, an exclamation mark (cut),
or a single word or number.
Variables are words which begin with an uppercase letter.
.pg
To execute a clause use the "<-" operator, for example:
.ce
[X] <- [[append [cons 1 [cons 2 nil]] [cons 3 nil] X]];
The left hand argument is a list which consists of the
variables whose values are to be printed out when
execution has terminated.
The list may be empty.
The right hand argument is a list of predicates which
must be "proved".
Note that the example above contains a list of only one
predicate.
.pg
The execution of a Prolog program may be traced by setting
the POP11 variable `tracing' to true.
Tracing can be swithched off by making false.
Alternatively, you can switch tracing on or off within
a Prolog program by including the 0-arity predicates
`trace' and `untrace', e.g.
.ce
[[f X Y] trace [g Z] untrace [q x]]
enables tracing of [g Z] only.
.sp
.ul
Built-in Predicates
.sp
.in 8
.np
[sum X Y Z]
is true if X + Y = Z. If any one of the three arguments is an
uninstantiated variable, it is instantiated.
.np
[integer X] true if X is an integer.
.np
[atom X] is true if X instantiates to an atom (not a variable).
.np
[variable X] is true if X is an unistantiated variable.
.np
[< X Y] is true if X and Y are both numbers and X < Y or if X and Y are
both words and X < Y.
.np
[output X] prints the term X. It does not print a newline.
If X is a POP11 string then `output' is equivalent to `prstring'.
.np
newline - 0-arity predicate which outputs a newline.
.np
[interm X] read a term and unify with X.
.np
[not X] - the usual meaning of `not'.
.np
[= X Y] unifies X with Y.
.np
[univ X Y] takes a Prolog term X and instantiates Y to a list
reresentation. For example, [f X Y] becomes
.ce
[. f [. X [. Y nil]]]
where the "." is the list constructor (same as "cons").
.np
[member X Y] is true if X is a member of the list Y
.in -8
.sp
.ul
The database
.pg
All clauses are stored in a list called "database".
It can be listed by typing:
.ce
: database==>
The POP11 database functions such as `lookup' and `match' may be
used to search the list.
.pg
For reasons of effeciency the user may wish to include some
of his own built-in functions written in POP11.
This is quite easy to do.
Look at the file %pop/usr/lib/prolog.p to see how it is done.
