You are on page 1of 2

1) Convert the following arithmetic expressions into Scheme expressions and evaluate

them.
a. 1.2 (2 - 1/3) + -8.7
b. (2/3 + 4/9) (5/11 - 4/3)
c. 1 + 1 (2 + 1 (1 + 1/2))
d. 1 -2 3 -4 5 -6 7

2) Determine the values of the following expressions. Use your Scheme system to verify
your answers.
a.
(cons 'car 'cdr)
b.
(list 'this '(is silly))
c.
(cons 'is '(this silly?))
d.
(quote (+ 2 3))
e.
(cons '+ '(2 3))
f.
(car '(+ 2 3))
g.
(cdr '(+ 2 3))
h.
cons
i.
(quote cons)
j.
(quote (quote cons))
k.
(car (quote (quote cons)))
l.
(+ 2 3)
m.
(+ '2 '3)
n.
(+ (car '(2 3)) (car (cdr '(2 3))))
o.
((car (list + - * /)) 2 3)

3) (car (car '((a b) (c d)))) yields a. Determine which compositions of car and
cdr applied to ((a b) (c d)) yield b, c, and d.

4) Define the predicate atom?, which returns true if its argument is not a pair and false if
it is.

5) The procedure length returns the length of its argument, which must be a list. For
example, (length '(a b c)) is 3. Using length, define the procedure shorter, which
returns the shorter of two list arguments. Have it return the first list if they have the same
length.
(shorter '(a b) '(c d e)) (a b)
(shorter '(a b) '(c d)) (a b)
(shorter '(a b) '(c)) (c)
6) In exercise 5) you used length in the definition of shorter, which returns the shorter
of its two list arguments, or the first if the two have the same length. Write shorter
without using length.
[Hint: Define a recursive helper, shorter?, and use it in place of the length comparison.]

7) Define the procedure make-list, which takes a nonnegative integer n and an object
and returns a new list, n long, each element of which is the object.
(make-list 7 '()) (() () () () () () ())
[Hint: The base test should be (= n 0), and the recursion step should involve (- n 1).
Whereas () is the natural base case for recursion on lists, 0 is the natural base case for
recursion on nonnegative integers. Similarly, subtracting 1 is the natural way to bring a
nonnegative integer closer to 0.]

You might also like