CS212 Exams
Spring 1998 - Prelim 1

Evaluation of Scheme Expressions


Determine the value to which the following Scheme expressions evaluate and draw a box around the resulting value. You need not show the steps in the substitution model needed to calculate the value.

 

a.
(head ((lambda (x) (cons x empty)) 3))


b.
(((lambda (x) (lambda (f) (f x))) 3) (lambda (y) (+ 2 y)))


c.
(tail (head (tail (cons 1 (cons (cons 2 (cons (cons 3 4) 5)) 6)))))


d.
(define foo (lambda (x) (lambda (y) (+ x y))))
(define bar (foo 3))
(+ (bar 4) (bar 7))


e.
((lambda (f) (lambda (x) (f 1 (f 2 x)))) +)


f.
(define baz 
   (lambda (f x a)
     (define 
       ((frob (lambda (y z) 
          (if (empty? y) z (frob (tail y) (f (head y) z))))))
      (frob x a))))

(baz + (list 1 2 3) 0)

Solution

Return to CS 212 Prelim 1 - Spring 1998