Logic Languages
Prolog
- Prolog has the simplest syntax and semantics of any programming language, but yet is extremely powerful.
<predicate> [:- <predicate_list>].
where <predicate> is <name>(<parameter_list>)
Prolog is very similar to a functional language, but does not require the embedding of function references to provide sequencing of action.
The sequence of execution of Prolog statements depends on which statement is applicable in the current state of the machine.
A Prolog program consists
of a database of predicates composed of facts and rules involving constants and variables.
Variables are identified by character strings that start with an upper case character - such as X, Y, Number, Constant.
Constants are similarly character strings but with a first character that is in lower case - x, y, number, constant.
A predicate is
a function whose result is either true or false.
A fact is just something
that is always true about some constants; i.e. has no conditional clauses:
Peggy is the mother
of George.
In Prolog:
mother (peggy, george).
NOTE the period at the end of each rule. This is another use of "Forward Polish" notation where the relationship precedes the operands.
A rule is an implication (predicate)
involving variables:
If X is the mother of Y and Y is a parent of Z, then X is a grandmother
of Z. Or put the "Prolog" way, X is the grandmother of Z provided that X is the mother of Y and Y is a parent of Z.
In Prolog:
grandmother(X,Z) :- mother(X,Y),
parent(Y,Z).
In Prolog read ":-" as "provided that" and "," as "and". Though not shown here, Prolog uses ";" in rules to mean "or".
Tutorial Help:

![[TOC]](TOC.gif)
CS1104
Main Page
Last Updated 11/03/2000
©
J.A.N. Lee, 2000