Getting Started 11
dog(henry)
cat(X)
>(3,2)
person('john smith',32,doctor,london)
Each argument of a compound term must be a term, which can be of any kind
including a compound term. Thus some more complex examples of compound
terms are:
likes(dog(henry),Y)
pred3(alpha,beta,gamma,Q)
pred(A,B,likes(X,Y),-4,pred2(3,pred3(alpha,beta,gamma,Q)))
(5) Lists
A list is often considered to be a special type of compound term, but in this book it
will be treated as a separate type of data object.
Lists are written as an unlimited number of arguments (known as list elements)
enclosed in square brackets and separated by commas, e.g. [dog,cat,fish,man].
Unlike the arity of a compound term, the number of elements a list has does not
have to be decided in advance when a program is written, as will be explained in
Chapter 9. This can be extremely useful.
At this stage, all that it is necessary to know is that an element of a list may be a
term of any kind, including a compound term or another list, e.g.
[dog,cat,y,mypred(A,b,c),[p,q,R],z]
[[john,28],[mary,56,teacher],robert,parent(victoria,albert),[a,b,[c,d,e],f],29]
[[portsmouth,edinburgh,london,dover],[portsmouth,london,edinburgh],[glasgow]]
A list with no elements is known as the empty list. It is written as [].
(6) Other Types of Term
Some dialects of Prolog allow other types of term, e.g. character strings. These
will not be described in this book. However, it is possible to use atoms to perform a
rudimentary type of string processing (see Chapter 10).
Atoms and compound terms have a special importance in Prolog clauses and
are known collectively as call terms. We will return to this in future chapters.
Chapter Summary
This chapter shows how to write simple Prolog programs, load them into the
Prolog database and enter goals that can be evaluated using them. It also introduces
basic terminology and the different types of data object (terms).