Directions

Work alone. You may not discuss these
problems or anything else related to this course with anyone except for
the course staff between receiving this exam and class Monday.

Open book. You may use any books you want, lecture notes and
slides, your notes, and problem sets. If you use anything other than
the course books and notes, cite what you used.

No DrScheme. You may not run DrScheme or use
any other Scheme interpreter between now and when you turn in this
exam.

Answer well. Answer all 10 questions. Write your answers on
this exam. You should not need more space than is provided to write
good answers, but if you want more space you may attach extra sheets.
If you do, make sure the answers are clearly marked.

The questions are not necessarily in order of
increasing difficulty, so if you get stuck on one question you should
continue on to the next question. There is no time limit on this
exam, but it should not take more than a few hours to complete.

Full credit depends on the clarity and elegance of your
answer, not just correctness. Your answers should be as short and
simple as possible, but not simpler.

Evaluation

Due to an unfortunate snowboarding incident, Ben Bitdiddle has become
muddled. For each expression below, explain:

What the Scheme interpreter will produce when the expression is
evaluated

The Scheme interpreter will produce an error. The expression is an
application, so according to Evaluation Rule 3a we should evaluate each
subexpression. Each subexpression is a primitive, so they all
self-evaluate. Then, according to Evaluation Rule 3b, we should apply
the value of the first subexpression (3) to the values of all
the other subexpressions. We have application rules for primitive
procedures and compound procedures, but 3 is not a procedure,
so no application rule applies and an error is reported.

(+ 3 4)

1. Make a list containing the number 1, 2 and 3 in order:
(cons 1 (cons 2 3))

Explain what the Scheme interpreter will produce when the expression is
evaluated?

How should the expression be fixed to produce what Ben wants?

2. Divide every number in lst by 7 (assume lst
is already defined to a list of numbers):

(map (/ x 7) lst)

Explain what the Scheme interpreter will produce when the expression is
evaluated?

How should the expression be fixed to produce what Ben wants?

3. Define a procedure is-even? that evaluates to
#t when applied to an even number, and evaluates to #f
when applied to an odd number:

9. Define a procedure lastelement that takes a list as
input and evaluates to the last element in that list. For example,
(lastelement (list 1 2 3 4)) should evaluate to 4.

10. Define a procedure lastsatisfyingelement that takes a
list and a procedure as input, and evaluates to the last element in the
list for which applying the procedure to that element evaluates to
true. For example,

(lastsatisfyingelement (list 1 2 -3 4 -5 7 -9)
(lambda (x) (> x 0)))

should evaluate to 7.

These two questions are optional and worth no credit, but we appreciate
your answers. Please answer them on the back of this page.

11. Do you feel your performance on this
exam will fairly reflect your understanding of the course material so
far? If not, explain why.

12. Do you have any
comments about how the course is going so far or suggests for improving
the remainder of the course?