Suppose our database includes information not only about animals
but also the location and opening times of zoos, for instance:
zoo(jersey, address('Les Augres Manor, Trinity, Jersey'),
open(10), close(dusk)).
We could envisage wanting to know which zoos had certain animals and
also wanting to know the opening times of these zoos.
We'll assume that (for the time being) we have only the following
animal recorded in the database:
mammal(gorilla, 'n''gola', female, parents(mother('n''pongo'),
father(jambo)), 1988, jersey).
To link the two structured objects, we need to find an argument they
have in common. The obvious one is the name of the zoo. Our query
has to clearly show that the value of the first argument in zoo/4
is the same as that of the sixth argument in mammal/6. So far we have
seen only one practical way of doing this and this is by using a single
variable.
| ?- mammal(gorilla, Name, Sex, Parents, DoB, Zoo),
zoo(Zoo, Address, Open, Close).
Name=n'gola
Sex=female
Parents=parents(mother(n'pongo), father(jambo))
DoB=1988
Zoo=jersey
Address=address('Les Augres Manor, Trinity, Jersey')
Open=open(10)
Close=close(dusk)
Let's look at the hypothesis that this query is forwarding:
- there is a structured object in the database called mammal
- this structured object has six arguments
- the first argument must unify with the atom "gorilla"
- the remaining five arguments will unify with the remaining
five variables "Name, Sex, Parents, DoB, Zoo"
- there is a structured object in the database called zoo
- this structured object has four arguments
- the first argument must unify with whatever Zoo was unified
with in the fourth part of the hypothesis
- the remaining three arguments will unify with the remaining
three variables "Address, Open, Close"
If all these conditions are true, then the hypothesis has been proved.
We can say that this query consists of two goals. The two
goals are joined by the use of the comma, ",". The comma is an important
part of Prolog, because it can always be read as meaning "and".
The comma is often called the conjunction.
|