PLOGHELP GLOSSARY                           Kathryn Seifert  July 1986

Definitions of some terms used in describing Prolog programs.


         CONTENTS - (Use <ENTER> g to access required sections)

 -- ARGUMENT
 -- ARITY
 -- BODY
 -- CLAUSE
 -- COMPONENT
 -- DATABASE
 -- FACT
 -- FUNCTOR
 -- HEAD
 -- OPERATOR
 -- PREDICATE
 -- PROCEDURE
 -- STRUCTURE
 -- TERM


The following definitions are derived from PROGRAMMING IN PROLOG
(Clocksin and Mellish, 1981).

-- ARGUMENT -----------------------------------------------------------

In a Prolog term such as :

    traps(steve, lion)

the names of the objects that are enclosed in parentheses (i.e. "steve"
and "lion") are the ARGUMENTS.  'traps' is thus a predicate having two
arguments (it can also be said that 'traps' takes two arguments).


-- ARITY --------------------------------------------------------------

The ARITY of a predicate is the number of arguments it takes. Thus, the
predicate 'traps' as shown above has an ARITY of two.  In Prolog, this
fact would be represented by referring to the predicate as traps/2.

It is worth noting that if the following facts are placed in the
database:

    traps(steve, lion).
    traps(beatrice, anaconda, net).

the predicates traps/2 and traps/3 will be treated by Prolog as
completely different predicates.


-- BODY ---------------------------------------------------------------

Rules in Prolog consist of head and a BODY, which are connected by the
symbol ':-' (pronounced "if").  For example, in the following rule:

    eats(ruth, X) :- non_meat(X).

"eats(ruth, X)" is the head of the rule, and "non_meat(X)" is the body
of the rule.


-- CLAUSE -------------------------------------------------------------

A Prolog CLAUSE can be either a fact or a rule. For example,

    eats(ruth, eggs).
and
    eats(ruth, X) :- non_meat(X).

are both clauses. A predicate in Prolog is usually defined by a mixture
of facts and rules; these facts and rules are called the clauses for the
predicate.

Facts are sometimes referred to as unit clauses, as facts are
essentially rules with a head but no body.


-- COMPONENT ----------------------------------------------------------

A Prolog structure (see below) is specified by its functor (see below)
and its COMPONENTS.  So, in the following structure:

    eats(claude, chocolate)

"claude" and "chocolate" are the components and "eats" is the functor.
In general, the components of a structure may be any kind of Prolog term
(see below).

The arguments of a fact or rule are the same as the components of a
structure.


-- DATABASE -----------------------------------------------------------

A collection of facts and rules in Prolog is called a DATABASE.

See PLOGHELP * DATABASE for information about operations which can be
performed on the Prolog database.


-- FACT ---------------------------------------------------------------

A FACT is a clause which consists of a head but no body (thus facts are
sometimes referred to as unit clauses).  facts may be thought of as
asserting some sort of relationship between objects.  Thus the fact:

    enjoys_eating(claude, chocolate).

asserts that the relation "enjoys_eating" holds between the objects
"claude" and "chocolate".


-- FUNCTOR ------------------------------------------------------------

A Prolog structure (see below) is specified by its FUNCTOR (see below)
and its components.  So, in the following structure:

    eats(claude, chocolate)

"eats" is the functor; "claude" and "chocolate" are the components.

A functor of a structure is the same as the predicate of a fact or rule.


-- HEAD ---------------------------------------------------------------

Rules in Prolog consist of HEAD and a body, which are connected by the
symbol ':-' (pronounced "if").  For example, in the following rule:

    eats(ruth, X) :- non_meat(X).

"eats(ruth, X)" is the head of the rule, and "non_meat(X)" is the body
of the rule.


-- OPERATOR -----------------------------------------------------------

Functors are sometimes written a OPERATORS, in order to make structures
easier to read.  For example, the arithmetic operations are usually
written as operators.  In the following arithmetic expression:

    x * y + 3

the "times sign" and the "plus sign" are operators.  This expression
could be written in the way that Prolog structures are normally written:

    +(*(x, y), 3)

but this form makes the expression much more difficult to read.

Another operator that is commonly encountered in Prolog is the symbol
':-'.  Prolog rules are actually normal Prolog structures written in a
special form with the ':-' operator.  Thus, the rule

    eats(ruth, X) :- non_meat(X).

could be written as a Prolog structure with ':-' as a normal functor:

    :-(eats(ruth, X), non_meat(X)).

See PLOGHELP * OP for information about how to declare your own
operators.  See PLOGHELP * OPERATORS for information about the
declarations of the built-in Prolog operators.


-- PREDICATE ----------------------------------------------------------

In the Prolog clause

    traps(beatrice, anaconda, net)

'traps' is the PREDICATE of the clause, and the three terms 'beatrice',
'anaconda', and 'net' are the arguments of the clause.  The predicate
'traps' is said to have (or to take) three arguments.  Another way of
putting this is to say 'traps' has an arity of three.


-- PROCEDURE ----------------------------------------------------------

The collection of clauses for a given predicate is called a PROCEDURE.
For example, the clauses below comprise the procedure for 'append':

        append([],X,X).
        append(H.R,X,H.S) :- append(R,X,S).


-- STRUCTURE ----------------------------------------------------------

A STRUCTURE is a kind of Prolog term (the other kinds of terms are
variables and constants).  It is a single object which consists of a
collection of other objects (called components).  A Prolog structure is
written by specifying its functor and its components.  So, for example

    eats(claude, chocolate)

is a structure which has two components ("claude" and "chocolate") and
the functor "eats".

The components of a structure may be structures themselves:

    eats(beatrice, non_meat(X))

A Prolog structure may be considered the same as a Prolog clause.  A
predicate of a clause is a functor of a structure, and the arguments of
a clause are the components of a structure.

Lists in Prolog are a particular kind of structure, with a functor
called '.' (the dot). The components of this structure are the head and
the tail of the list.  Thus the list [a, b], is the same as the
structure:

    .(a, [b])


-- TERM ---------------------------------------------------------------

Prolog programs are constructed out of TERMS.  There are three kinds of
Prolog terms: variables, constants, and structures.  Thus all of the
following are terms in Prolog:

    (a) Prolog variables:

        e.g.    X
                Animal
                _1

    (b) Constants:

        e.g.    beatrice
                eats
                129
                :-
                ?-

    (c) Structures:

        e.g.    eats(claude, chocolate).
                offspring(Child, Parent1, Parent2) :-
                    parent(Parent1, Child),
                    parent(Parent2, Child).
                [a, prolog, list]

N.B. In some contexts, the word TERM is used to refer to Prolog
structures only.


--- C.all/plog/help/glossary
--- Copyright University of Sussex 1993. All rights reserved.
