CS212 Exams
Spring 1998 - Final

Solution to Brenda and Dylan

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.


(define-binding! 'select (make-brenda-special-form
  (lambda (args env)
    (let ((selector (brenda-eval (heads args) env)))
      (brenda-assert (integer? selector)
         "error : first argument must evaluate to an <integer>")
      (brenda-assert (> 0 selector)
         "error : selector value isn't positive")
      (letrec ((iter (lambda (position leftover)
                       (brenda-assert (not (empty? leftover))
                          "error : not enough values to select from")
                       (if (= position 1)
                           (brenda-eval (head leftover) env)
                           (iter (- position 1) (tail leftover))))))
        (iter selector (tail args)))))))

Question

Return to CS 212 Final - Spring 1998