This section introduces a simple animal classifier. Please start by
animals knowledge base. Make
a printed copy of it if you want, too. You can look at it by
showlib animals.pl from Prolog, and print it by
ctcprint from VED.
The classifier is similar to the ski advisor of Supplement 1, but unlike
latter, it contains some unary (one-argument) predicates, such as
flies. There are none
with more than two arguments, but you will see some of these later, in
the trading game.
A complete list of predicates follows. After each, I have stated what I
intend it to mean. For example, from the description of
you can see that the fact
spots( pip, black ).means Pip has black spots.
chews_cud(A): A is an animal which chews its cud.
colour(A,C): A is an animal whose colour is C (
eats(A,F): A is an animal that eats food type F (
eye_direction(A,D): A is an animal whose eyes point in direction D (
flies(A): A is an animal that can fly.
gives_milk(A): A is an animal that gives milk.
has(A,P): Animal A has body part P (
is_a(C1,C2): Class C1 of animals is included in class C2. The names of classes (including the animals themselves) are
lays_eggs(A): Animal A lays eggs.
long_legs(A): Animal A has long legs.
long_neck(A): Animal A has a long neck.
spots(A,C): Animal A has spots of colour C.
stripes(A,C): Animal A has stripes of colour C.
swims(A): Animal A can swim.
Notice that I have taken care to indicate what type of thing each
argument refers to, and what the names used for individuals of each type
are. For instance I have listed the body parts used in the second
has. If you write programs for yourself, it is important to
make sure that you know what each predicate does,
how many arguments it
has, what can go in or come out, and which order the arguments are in.
It is all too easy to think that you should write
elsewhere you have
gives_milk(A); that you should write
colour(A,dark) when elsewhere you have
color(A,black); that you
lays(eggs,A) when elsewhere you have
When writing down such information, you need not be as formal as
I have, but you should note it down somehow. If you have programmed
before, you will know that most computer languages let you put such
notes as comments in your
Care is especially necessary because Prolog does not detect spelling errors. Usually they just make it say ``No''. For instance, suppose you have the fact
colour( pip, black ).and you ask
colour( Who, dark ).Prolog treats
darkas completely different from
black, and will say
no, when what you want is probably
Yes - Who=pip. The same would happen if you were to ask
colour( dark, Who ). black_colour( Who ).