@comment(Hey, EMACS, this is -*- SCRIBE -*- input)
@make(6001)
@set(chapter=1)
@set(page=1)

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

@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)

@begin(format)
Issued: Tuesday, 5 April 1983@>Due:Wednesday, 13 April 1983

Reading Assignment: Chapter 5
@end(format)

@blankspace(0.25 in)

@b[Note: Quiz 2 will be held on Thursday, 14 April 1983 at 5-7 xor
7-9 PM in Walker Memorial Gymnasium (room 50-340).  The exam will
cover material on state and side-effects, environments and evaluation,
and streams.  As usual, this is an open book exam.]

@blankspace(0.25 in)

@begin(center)
@b[Exercises]
@end(center)

@blankspace(0.25 in)

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

@begin(itemize)
Exercise 1, page 259

Exercise 2, page 261

Exercise 4, page 262

Exercise 5, page 262
@end(itemize)

@blankspace(0.25 in)

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

Start Scheme and load in the files:
@begin(programexample)
(load "<ls.source>ps8-query")
(load "<ls.source>ps8-data")
@end(programexample)

The first file is the query language implementation, as described in
Chapter 5 of the notes.@foot{Well, not quite.  The pattern matcher and
unifier have been recoded so that they appear in Scheme as primitives,
rather than as compound procedures.  This makes the system run twice
as fast as it would otherwise.} The second file reads in and
initializes the personnel data base for the Itsey Bitsey Machine
Company, as given in section 5.1.1, together with the @a[outranked-by]
and @a[lives-near] rules given on page 261.

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 1
(p. 259) and exercise 2 (p. 261).

Do exercise 3 (p. 262).  (See page 271 for how to add new rules.)
@begin(itemize)
Warning 1: 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 only way to get rid of a bad rule is to
reload Scheme.

Warning 2: The second of the two tests of your rule (all people who
can replace someone who is being paid more than they are) severely
pushes the limits of our poor DEC 20, if the system is very busy, you
may want to punt on actually typing this one in, or else bring a good
novel to read while waiting.
@end(itemize)

Do exercise 11 (page 286).  Please note the following:
@begin(itemize)
There are some minor misprints in the description of the exercise, in
the form of the input queries that demonstrate how your new system
should work.  The input on the bottom of page 286 should read
@begin(programexample)
@d[query-->](unique (job :x (computer wizard)))
@end(programexample)
and the two queries at the top of page 287 should read
@begin(programexample)
@d[query-->](unique (job :x (computer programmer)))

@d[query-->](and (job :x :j)
             (unique (job :anyone :j)))
@end(programexample)


You do not need to make any changes to the @a[ps8-query] code in
order to implement @a[unique].  Merely set up a small Emacs 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 Emacs and Scheme. Each time you
modify the definition of @a[uniquely-asserted?] and read it back into
Scheme, be sure to also read in and execute the @a[put] command.
Otherwise, you will change the procedure definition, but @a[qeval]
will still dispatch to the old procedure.
@end(itemize)
@end(itemize)

@blankspace(0.25 in)

@begin(center)
@b[Post-Lab Written Work]
@end(center)

Write up and turn in thoughtful answers to the following exercises from
Chapter 5 of the notes.
@begin(itemize)
Exercise 7, page 273

Exercise 8, page 273

Exercise 10, page 274
@end(itemize)