@make[report]
@device[dover]
@style[font=helvetica10]
@set(page=1)

@PageHeading(even,
             left "@Value(Page)",
             right "6.001 -- Fall Semester 1984")

@PageHeading(odd,
             Left "Problem Set 9",
             right "@value(page)")

@begin(center)
MASSACHUSETTS INSTITUTE OF TECHNOLOGY
Department of Electrical Engineering and Computer Science
6.001 Structure and Interpretation of Computer Programs

Problem Set 9
@end(center)
@blankspace(0.25 in)

Issued: Tuesday, 20 November 1984

Due: Friday, 30 November 1984 for ALL recitation sections

Reading Assignment: Chapter 4, Section 4.5
 
@blankspace(0.25 in)
 
@begin(center)
@b[Exercises]
@end(center)

@blankspace(0.25 in)

Write up and turn in the following exercises from Chapter 4 of the text.


@begin(itemize)
Exercise 4-27, page 343

Exercise 4-28, page 345

Exercise 4-30, page 346

Exercise 4-31, page 346
@end(itemize)

@blankspace(0.25 in)

@begin(center)
@b[Programming assignment]
@end(center)


You will not be doing any programming in Scheme for this problem set.
Instead you will be programming in the "query language" described in
Chapter 4.  Use the @i[load-problem-set] command to load the query language
and the data base given in Section 4.4.1, together with the
@i[outranked-by] and @i[lives-near] rules given on page 345-6.  As you will
notice, this version of the language is not very efficient.  To avoid
slowing it down, be sure @i[not] to load the source code for the language
from the editor -- the version you get from @i[load-problem-set] has been
run through a simple optimizer which may speed the code up by as much as
25% (we haven't timed it).

In order to make it easier to type complicated queries, we have added a
command to the query language that will let you use the editor.  If you
type @i[(edit)] to the @i[query-->] prompt, it will return you to the
editor.  You can use the editor to compose a query and @i[zap] one query
down at a time.  Use the @i[zap define] function to mark exactly one query
to be executed; then use the @i[scheme] function to get back to the query
language.  Do not use the @i[edit] key on the terminal; that is like typing
^G and then @i[(edit)], which will get you out of the query language (back
into Scheme) and then into the editor.

Don't forget to end anything you type to the @i[query-->] prompt with the
@i[execute] key, just like you would at the normal Scheme ==> prompt.

Once you have read the files in, you should be able to start the system by
typing
@begin[programexample]
(query-driver-loop)
@end[programexample]
@begin(itemize)
Try out the system by typing in queries as specified in exercise 4-27
(p. 343) and exercise 4-28 (p. 345).

Do exercise 4-29 (p. 346).  (See page 356 for how to add new rules.)

@begin[itemize]
Warning: The system as we have implemented it includes no way to
@i[get rid of] rules.  Thus, if you define a bad rule, and then define
a good rule with the same name, @i[both] rules will stay around to be
used by the system.  The best way to get rid of a bad rule is to
call in Scheme
@end[itemize]
@begin[programexample]
	(initialize-data-base ibm-data-base)
@end[programexample]

Do exercise 4-41 (page 380).  You do not need to make any changes to the
query language code in order to implement @i[unique].  Merely set up a
small file of your own with the new code to be added to the query
interpreter.  Note that during the debugging of your program, you will
probably be switching back and forth between the editor and Scheme.  Each
time you modify the definition of @i[uniquely-asserted?] and read it back
into Scheme, be sure to also read in and execute the @i[put] command.
Otherwise, you will change the procedure definition, but @i[qeval] will
still dispatch to the old procedure.

@end(itemize)
@blankspace[0.25 inches]
@begin[center]
@b[Post-Lab Written Work]
@end[center]
Write up and turn in thoughtful answers to the following exercises from
Chapter 4 of the notes.

@begin(itemize)
Exercise 4-35, page 359

Exercise 4-36, page 359

(Optional - hard) Exercise 4-38, page 360

@end(itemize)


@blankspace(0.25 in)

