52 349 Logic Programming

Practical 2

  1. Complete Practical 1:

    1. Test your file of family relationships on one of the files in the royalty series. This is why the warning paragraph about parent/3 as opposed to parent/2 appeared earlier. After all, royalty doesn't specify anything about parent/2, does it?

    2. Later in the term, extend one of the family relationships (grandparent, perhaps?) so that it repeatedly reads an atom and then writes out one grandparent , until such time as you enter some keyword such as end; test this on royalty. Why - assuming you find it to be the case - do successive queries about a particular person always generate the same grandparent, and not successive, different grandparents?

  2. For some of the people recorded in royalty, there is a record of their dates of birth and death. Dates are stored as lists [day,month,year] and the relevant information is available through lived(Person,Birth_date,Death_date). Write the predicate which determines the person or persons alive in a particular year. When doing this, you should ignore days and months (in other words, assume all birthdays are 1 January and all death days 31 December!).

    Feel free to extend the exercise to some specific [day,month,year]. But make sure before you spend time on it that you can handle the later exercises which form Practical 3! Given that year zero is used in royalty to denote "don't know", your answers to (2) will include some distinctly elderly people; add predicates to exclude those who have a birth year of zero - or, to be more realistic, assume that (unless recorded to the contrary) women died at age forty and men at age sixty.

  3. Modify one of the predicates used in question one, so as to produce a list of all people in some given family relationship with a given person. This isn't quite as simple as it seems; probably you will want to use either recursion or a failure driven loop. For test data, try some of the Scots who were alive towards the end of the fifteenth century.

    If this exercise causes you difficulty, you may find it advisable first to tackle Practical 3's exercise (2).

© Paul Goldfinch 1996 Return to 52 349 Menu