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.
The important thing is that each node in the original tree has a corresponding node in the tree that diagrams the query. The leaf nodes are variables in this example.
I have used the empty triangle to indicate that the variable will stand for the node and everything growing from it.
These Pages are maintained by
Dr Peter Hancox
Last updated October 1998