Self-test 1
Family tree example with alternatives
You are advised to complete your solutions before you look at
the answers.
-
Write facts to represent the following family tree, using the procedures
male/1, female/1, parent/2:
-
Write a procedure called grandparent/2 to express the grandparent
relation. Test this by finding all grandparents in this tree.
-
Use the grandparent/2 procedure in writing
grandmother/2
and grandfather/2 relations. Test these by finding all grandmothers
and grandfathers in the tree.
-
Write a procedure called ancestor/2 which is given the name as
the first argument and returns an ancestor as the second argument.
-
Draw a search tree for the query ancestor(andrew, benjamin).
Solutions