CS212 Exams
Spring 1999 - Prelim
2

OO Programming II


Write a generic function dir which, when given a file system object, always prints out the name of the object, as well as what type of object it is. In addition, if the object is a directory, the function should print out the names of the objects contained in the directory, but it should not print out the contents of any sub-directories. If the object is a symbolic-link, then the function should print out the name of the object the link refers to. For example, if our file system looks like the one pictured below, where C:, Windoze, and Temp are directories; C-link is a symbolic link; and foo.txt, bar.txt, and baz.txt are documents, then the dir should work as follows (assuming the appropriate symbols are bound to the appropriate objects):

==> (dir fs:c-object)
C: directory.  Contents: Windoze Temp
==> (dir fs:windoze-object)
Windoze directory.  Contents: foo.txt bar.txt
==> (dir fs:temp-object)
Temp directory. Contents: C-link baz.txt
==> (dir fs:foo-object)
foo.txt document.
==> (dir fs:c-link-object)
C-link symbolic-link to C:

Solution

Return to CS 212 Prelim 2 - Spring 1999