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

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

@PageHeading(odd,
             Left "Problem Set 8",
             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 8
@end(center)
@blankspace(0.25 in)

Issued: Tuesday, 24 April 1984

Due:

@begin(itemize)
on Wednesday, 2 May 1984
for recitations meeting at 12:00, 1:00, and 2:00

on Friday, 4 May 1984
for recitations meeting at 9:00, 10:00, and 11:00
@end(itemize)

Reading Assignment: Chapter 4, Sections 4.3 and 4.4

@blankspace(0.25 in)

Video tapes: Video tapes are provided as an optional service for people
who want to review course material.  Tapes are available in Barker
library.

@begin(programexample)
Tape number        Corresponding section         Corresponding Lecture
                         in notes

 1                         1.1                      Feb. 9
 2                         1.2                      Feb. 14
 3 and 4                   1.3                      Feb. 16
 5                         2.1                      Feb. 23
 6                         none                     Feb. 28
 7-8                       2.2                      March 1 and March 6
 9 (extra material         none                     none
    on pattern matching)
10			   2.3			    March 8
11			   2.4			    March 13
12			   3.1			    March 14
13			   3.2			    March 20
14 (first 20 minutes)	   3.3			    March 22
14 (last 30 minutes)       3.4                      April 3
15                         3.4                      April 3
16                         3.4                      April 5
17                         4.1                      April 10
18                         4.2                      April 12
19 (first 15 minutes)      4.2                      April 12
19 (last 15 minutes)                                April 25
20                                                  April 26
21                         Chapter 5                May 1
22                         Chapter 5                May 3
@end(programexample)
@newpage
@begin(center)
@b[Exercises]
@end(center)

@blankspace(0.25 in)

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

@begin(itemize)
Exercise 4-17, page 268

Exercise 4-18, page 269

Exercise 4-20, page 271

Exercise 4-21, page 271
@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.3.1, together with the
@i[outranked-by] and @i[lives-near] rules given on page 270.  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-17
(p. 268) and exercise 4-18 (p. 269).

Do exercise 4-19 (p. 270).  (See page 280 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-27 (page 296).  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-23, page 282

Exercise 4-24, page 282

(Optional - hard) Exercise 4-26, page 283

@end(itemize)


@blankspace(0.25 in)

