CS212 Exams
Spring 1998 -
Final

Solution to Destructive Programming

WARNING: You should seriously try to answer this question before looking at the solution -- it's just a good study skill. Also, some answers on this page may be more brief than you would want to put down in an actual exam. If you want any type of partial credit, you should write more than just the solution.


  1. (define (append! x y)
    (letrec ((iter (lambda (z)
                     (if (empty? (tail z))
                       (set! (tail z) y)
                       (iter (tail z))))))
            (if (empty? x)
              y
              (begin (iter x) x))))
  2. It loops forever, or crashes when stack space runs out.

  3. (define zardoz
      (let ((x 6))
        (lambda ()
          (set! x (- 13 x))
          x)))

Question

Return to CS 212 Final - Spring 1998