Self-test 1

Family tree example with alternatives

You are advised to complete your solutions before you look at the answers.
 
 
  1. Write facts to represent the following family tree, using the procedures male/1, female/1, parent/2:


  2.  
     

  3. Write a procedure called grandparent/2 to express the grandparent relation. Test this by finding all grandparents in this tree.
  4. Use the grandparent/2 procedure in writing grandmother/2 and grandfather/2 relations. Test these by finding all grandmothers and grandfathers in the tree.
  5. Write a procedure called ancestor/2 which is given the name as the first argument and returns an ancestor as the second argument.
  6. Draw a search tree for the query ancestor(andrew, benjamin).

  7.  

     

Solutions

--------------------------------------------------------------------------

Navigation Menu

--------------------------------------------------------------------------