We have already seen how to form queries for structured objects
without nested structured objects within them. Querying structured
objects within structured objects is only a small step further on.
To recap briefly: we saw with the simple examples (such as mammal(gorilla,
jambo).) that we may use either atomic terms or variables to
stand for each argument. With structured objects within structured
objects, we have to ensure that each item in the nested structured
object is covered by either a term or a variable. To illustrate
in more detail, let's look again at an example we diagrammed above:
parents(mother('n''pongo'), father(jambo)).
There are a range of possible queries:
| ?- parents(mother(Mum), father(Dad)). 1
Mum=n'pongo
Dad=jambo
| ?- parents(Mum, Dad). 2
Mum=mother(n'pongo)
Dad=father(jambo)
| ?- parents(mother('n''pongo'), father(Dad)). 3
Dad=jambo
and you could probably devise a few more.
We'll look again at the diagrams and we should be able to see how
the three queries match the structured object.
|