Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Prolog terminology. Given the following set of Prolog clauses father(X,Y):-paren

ID: 3889338 • Letter: P

Question

Prolog terminology. Given the following set of Prolog clauses father(X,Y):-parent(X,Y),male(X) parent(sally,bob). parent(jim,bob). parent(alice,jane). parent(thomasjane) male(bob) male(jim). male(thomas). female(sally). female(alice) (a) How many atoms are matched to the variable X before the following query reports a result: ?-father(X.jane) b) What will the variable X be bound with when the query ?-father(Xjane). reports a result? (c) How many different facts are given in this Prolog program? (d) How many different rules are given in this Prolog program? (e) How many different variables are used in this Prolog program? ( How many different atoms are specified in this Prolog program? (g) Add a rule that states parent bill had only sons (no daughters) and every such son became a parent of a child named frank, walter, or george.

Explanation / Answer

+X

This denotes an input argument. Such an argument must be instantiated before a built-in is called.

-X

This denotes an output argument. Such an argument must be not instantiated before a built-in is called.

?X

This denotes an input or an output argument. Such an argument may be either instantiated or not when a built-in is called.

Arity

Arity is the number of arguments to a term. Atoms are considered as functors with zero arity. The notation Name/Arity is used to specify a functor of name Name with arity Arity.

Atom

An arbitrary name chosen by the user to represent objects from the problem domain. A Prolog atom corresponds to an identifier in other languages.

Atomic

An atom, string or a number. A terms which does not contain other terms.

Body

A clause body can either be of the form

or simply

Each Goal_i must be a callable term.

Built-in Procedures

These are predicates provided for the user by the ECLiPSe system, they are either written in Prolog or in the implementation language (usually ``C'').

Clause

See program clause or goal.

Callable Term

A callable term is either a compound term or an atom.

Compound Term

Compound terms are of the form

where f is the functor of the compound term and t_i are terms, n is its arity. Lists and Pairs are also compound terms.

DID

Each atom created within ECLiPSe is assigned a unique identifier called the dictionary identifier or DID.

Difference List

A difference list is a special kind of a list. Instead of being ended by nil, a difference list has an uninstantiated tail so that new elements can be appended to it in constant time. A difference list is written as List - Tail where List is the beginning of the list and Tail is its uninstantiated tail. Programs that use difference lists are usually more efficient and always much less readable than programs without them.

Dynamic Procedures

These are procedures which can be modified clause-wise, by adding or removing one clause at a time. Note that this class of procedure is equivalent to interpreted procedures in other Prolog systems. See also static procedures.

ElemSpec

An ElemSpec specifies a global variable (an atom) or an array element (a ground compound term with as much arguments (integers) as the number of dimensions of the array).

External Procedures

These are procedures which are defined in a language other than Prolog, and explicitly connected to Prolog predicates by the user.

Fact

A fact or unit clause is a term of the form:

where Head is a structure or an atom. A fact may be considered to be a rule whose body is always true.

Functor

A functor is characterised by its name which is an atom, and its arity which is its number of arguments.

Goal Clause

See query.

Ground

A term is ground when it does not contain any uninstantiated variables.

Head

A head is a structure or an atom.

Instantiated

A variable is instantiated when it has been bound to an atomic or a compound term as opposed to being uninstantiated or free. See also ground.

List

A list is a special type of term within Prolog. It is a recursive data structure consisting of pairs (whose tails are lists). A list is either the atom [] called nil as in LISP, or a pair whose tail is a list. The notation :

is shorthand for:

Name/Arity

The notation Name/Arity is used to specify a functor of name Name with arity Arity.