COMP9414/9814 Artificial Intelligence

Review Questions on Prolog Programming - Part 1

This is a voluntary quiz to help you decide whether you have understood some of the major concepts from this topic. It carries no marks.

  1. What are the differences between a procedural programming language and a declarative programming language? Is Prolog procedural or declarative?

  2. Given the file facts03 described in lectures, what solutions will Prolog find to the query studies(henry, What). ? Work out the answer yourself from the list of facts, and then check your answer using the Prolog interpreter.

  3. Write a query which will answer the question: "What student(s) in year 2 study 9414?" using the facts in facts03. What will the answer be?

  4. Write a rule to define the property of being in year 1 and enrolled in a course. The header comment would be:
    % year1stud(Student, Course) succeeds if Student is in year 1
    % and Student is studying Course.

    Now write a rule that defines the property of being in year 1 and enrolled in any course but we don't care what. The header comment would be:
    % enrolledyear1stud(Student) succeeds if Student is in year 1
    % and Student is studying something, as opposed to being on leave, say.

    Try this second one two ways - using a don't-care variable, and using a normal variable in place of the don't care variable. Load both versions into Prolog and check for warning messages. If you don't understand the warning message, read about singleton variables in the Prolog Dictionary.

  5. Write rules to define a bad dog. A dog is bad if it bites the postman, chews the newspaper, or chases the cat. Make up your own predicates for biting and chewing and chasing.

  6. Invent Prolog structures to describe a person. The person should have family name, a given name, and a middle initial (think George W Bush). They should also have a date of birth, an address, and a star-sign (like Aries or Libra or Leo). The address should consist of a country, a state, a town or suburb, and a street address, which should consist of an apartment number, a street number, a street name, and a street type (like Avenue or Road or Street). If they live in a house, not a block of flats, use 0 for the apartment number. Write down the structure that describes you.

Solutions: don't read until you've tried the questions yourself!

Bill Wilson's contact info

UNSW's CRICOS Provider No. is 00098G