Information Technology Reference
In-Depth Information
shown in this font .) To write your own Prolog programs, you will need to know
what is and is not allowed. So all the pieces are discussed in detail, starting with the
smallest ones.
Constants
A Prolog constant must start with a lowercase letter and can be followed by any num-
ber of letters, underscores, or digits. A constant may also be a quoted-string : any string
of characters (other than a single quote) enclosed within single quotes. The following
are all legal constants:
george
grand_father
mamboNumber5
'Who are you?'
Variables
A Prolog variable must start with an uppercase letter and can be followed by any
number of letters, underscores, or digits. The following are all legal variables:
X P12 MyDog The_biggest_number Parameter_26b
Prolog has other sorts of terms (numbers and lists) and other types of variables
(beginning with an underscore), which are discussed later.
Atomic sentences
The Prolog atomic sentences have the following form:
predicate ( argument 1 , ... , argument k )
where the predicate is a Prolog constant and the subsequent arguments are either Prolog
constants or variables. So, for example,
child(john,X) delivers_package('Fed Ex',Sender,Receiver)
are both atomic sentences, whereas
Rich(jim) likes(george,father(bill))
are not. (The first one has a variable in the predicate position, and the second one
has an argument that is not a constant or a variable.) Atomic sentences are sometimes
called atoms for short. Note that instead of john is a child of X , there is a pared-down
version child(john,X) , which omits many of the words used in the sentences in
chapter 2, puts the predicate at the front, and requires special punctuation:
Immediately after the predicate, there must be a left parenthesis.
 
Search WWH ::




Custom Search