Comp210
Due: 98.Sep.30 (Wed.) in class
You can test your function (and helper functions) traditionally.
If you like, we also provide you with a visual elevator simulator.
In DrScheme, ``Set Library to...'' teach/elevator-lib.ss
.
To start the elevator, simply evaluate
(run next-floor)after defining your function next-floor.
The simulator displays a picture of the elevator.
Clicking on call buttons adds floors to the request list.
(The up and down buttons behave identically.)
The simulator works by calling your
function next-floor repeatedly,
to decide the next floor to be visited.
Hint: You can check out the simulator immediately
by writing a very simple next-floor function. For example,
have next-floor always return the first
floor on the request list, or use this rather obstinate elevator controller:
(define next-floor (lambda (direction current-floor floor-requests) 3))This allows you to get started and see what the simulator looks like.
Be sure that your elevator controller is fair:
Every requested floor should eventually be visited,
regardless of the other requests in the list.
(This idea of fairness refers to making successive calls to
next-floor
, with an evolving request list.)
Hint: Split the list of requested floors into two
parts, those floors above the current floor and those
below. Use data definition and program templates
to derive appropriate helper functions for processing these
two pieces.
An ArithExp iswhere the ArithExps for
(make-real number)
(make-plus ArithExp ArithExp)
(make-times ArithExp ArithExp)
make-plus
andmake-times
are the arithmetic expression on each side of a plus sign or multiplication sign.
Note: The sum should stay unevaluated¹. If your input list contains seven numbers, the resulting arithmetic expression should consist of six uses of the constructor for plus applied to seven uses of the constructor for real; it should not be just a single use of the constructor for real.
count-unknowns
.
Write a few small test cases yourself;
here is a
medium-sized
test case.
To answer (by thinking, not w/ a program):
For a family tree whose size².
is five,
how many 'unknown
s does it contain?
(Is is possible for other trees of size five to contain more or less?)
How many 'unknown
s in a family tree of size seven?
Of size n?
ArithExp
.
This would let us start to make sense of
(lambda (m n) (+ m 7 n))
.
Clearly the body of the lambda
is one of these generalized ArithExpr
s,
and we can't yet evaluate the expression
(until somebody would apply the lambda
to some actual down-to-earth numbers).
No, we won't actually make this extension to ArithExp
s,
although in the first two weeks of Comp311 you
write a program to interpret (most) Scheme
expressions -- the heart of DrScheme!
Using data definitions derived from the Law of Scheme,
this is quite managable...(and if you avoid using
data definitions and templates, it can be a mess!).
(back)
²
Remember, the size of a family tree is the number
the family trees involved (including itself).
Recall the function size
in class.
(back)