next up previous
Next: Analysis of Algorithms (30 Up: CS212 Preliminary Exam I Previous: CS212 Preliminary Exam I

Evaluation of Dylan Expressions (20 points)

Determine the value to which the following Dylan 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 ((method (x) (pair x '())) 3))

 \fbox {{\tt 3}}

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

\fbox {{\tt 5}}

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

\fbox {\tt (pair (pair 3 4) 5)}

 
d.
(define foo (method (x) (method (y) (+ x y))))
(define bar (foo 3))
(+ (bar 4) (bar 7))
\fbox {{\tt 17}}
 
e.
((method (f) (method (x) (f 1 (f 2 x)))) +)

\fbox {{\tt (method (x) (+ 1 (+ 2 x)))}}

 

f.
(define baz 
   (method (f x a)
     (bind-methods 
       ((frob (y z) 
          (if (null? y) z (frob (tail y) (f (head y) z)))))
      (frob x a))))

(baz + (list 1 2 3) 0)

\fbox {{\tt 6}}

 


next up previous
Next: Analysis of Algorithms (30 Up: CS212 Preliminary Exam I Previous: CS212 Preliminary Exam I
Gregory Morrisett
3/11/1998