Lab 14:

Logic Programming

Logic programming excels in providing interfaces to data bases for information retrieval. The query language we shall use in this chapter is designed to be used in this way.

Labwork

finish this during section

For all problems that involve writing queries or rules, test your solutions. To run the query system and load in the sample data:

> (load "~cs61a/lib/query.scm")
> (initialize-data-base microshaft-data-base)
> (query-driver-loop)

You're now in the query system's interpreter. To add an assertion:

(assert! (foo bar))

To add a rule:

(assert! (rule (foo) (bar)))

Anything else is a query.

Exercise 1.

Abelson & Sussman, exercises 4.55 and 4.62.

Homework

do this in section if possible; finish the rest at home

Exercise 2.

Abelson & Sussman, exercises 4.56, 4.57, 4.58 and 4.65.

Exercise 3.

That's it! Go study for the quizzes and final. Finish project 4 if you haven't yet.

Extra for Experts

Do this if you want to. This is NOT for credit.

Exercise 4.

The lecture notes for this week describe rules that allow inference of the reverse relation in one direction, i.e.,

;;; Query input:
(forward-reverse (a b c) ?what)

;;; Query results:
(FORWARD-REVERSE (A B C) (C B A))

;;; Query input:
(forward-reverse ?what (a b c))

;;; Query results:
... infinite loop

or

;;; Query input:
(backward-reverse ?what (a b c))

;;; Query results:
(BACKWARD-REVERSE (C B A) (A B C))

;;; Query input:
(backward-reverse (a b c) ?what)

;;; Query results:
... infinite loop

Define rules that allow inference of the reverse relation in both directions, to produce the following dialog:

;;; Query input:
(reverse ?what (a b c))

;;; Query results:
(REVERSE (C B A) (A B C))

;;; Query input:
(reverse (a b c) ?what)

;;; Query results:
(REVERSE (A B C) (C B A))