CS212 Exams
Spring 1999 - Prelim 2

Solution to OO Programming II

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.


(defgeneric (dir file-obj))

(defmethod (dir (file-obj <document>))
  (echo (name file-obj) "document."))

(defmethod (dir (file-obj <symbolic-link>))
  (echo (name file-obj)
         "symbolic link to"
         (name (object file-obj))))

(defmethod (dir (file-obj <directory>))
  (echo (name file-obj) "directory. Contents:")
  (for-each (lambda (y) (echo (name y)))
            (contents file-obj)))

Question

Return to CS 212 Prelim 2 - Spring 1999