CS 1102 (A06) Homework 3: Complex Data Definitions

Due: September 14 (Thursday) at 11:59pm.

Assignment Goals


The Assignment

Mutual Recursion

For an operating systems class, you've been asked to implement a simple filesystem. The HTDP text provides three models for filesystems. Use Model 3, the one at the bottom of the page, for these exercises.

If you want to test your filesystems programs on a real filesystem (your own, for example), use the dir.ss library described in HTDP, exercise 16.3.1.

In these exercises, a "filesystem" is a directory (the root directory). Functions over "filesystems" should therefore follow the template for dir (where dir is as defined in the HtDP model).

You should use map and filter whenever appropriate in your solution. This means that if a function matches the structure of map or filter, you should write it using map/filter. You do not need to re-arrange solutions to use map/filter (even if they have one solution that uses them and one that does not). If you are still shaky with map/filter, write the solutions without map/filter first, then look for places where you could rewrite your solutions with them (you'll get more points for a solution that matches the template but misses map/filter calls than for solutions that don't correctly solve the problem.) Map/filter solutions still follow the templates!

Warning: One common error on these problems is mixing up the positions of files and subdirectories when you make your examples of data and test cases. You then spend a lot of time "debugging" code that is correct around buggy examples. Double check your examples carefully to make sure you haven't done this. One indication that you are having this problem is an error about no matching cond clause in one of your programs -- that usually means that you put the wrong type of data somewhere in your data structure.

  1. Write two examples of data created with the filesystem data definition.

    Note: Represent file and directory names as strings, not symbols as in HtDP.

  2. Write the template for programs over filesystems.

  3. Write a program contains-empty-files? that consumes a filesystem and produces a boolean indicating whether any file in the filesystem has a size of 0.

  4. Write a program disk-usage that consumes a filesystem and produces a number indicating the total size of all files.

  5. Write a program grep that consumes a string and a filesystem and produces a list of filenames of all files whose contents exactly match the string.

  6. Write a program rmdir that consumes a directory name and a filesystem, and returns a filesystem. In the returned filesystem, all directories with that name should have been removed if they contain no files and no subdirectories. All other files and directories should be the same between the input and returned filesystems.

  7. Write a program find-file-path that consumes a filename and a filesystem and returns either the path (a list of directory names, in order from root to the one containing the file) to that filename or false if the filename is not in the filesystem.

    Assume that the given file name is only in the system once.

  8. Write a program check-file-size that consumes a file and returns true if the file size matches the string-length of the file's contents. If the size and length do not match, check-file-size returns a string consisting of "size error: " followed by the offending file name. We will call any such program that consumes a file and returns a boolean or string a filechecker.

  9. Write a program check-all-files that consumes a filechecker and a filesystem and returns a list of all error messages (omit any successful files) that the filechecker generates on all files in the filesystem.

  10. Write a program compose-checkers that consumes two filecheckers and produces a filechecker. The resulting filechecker returns true if both input filecheckers do, the error message if either filechecker detects an error, and both error messages if both detect erors. Hint: use local.

  11. Write a program check-fs-size-name that consumes a filesystem to check all files for the correct size using check-file-size and that the filename is not the empty string "". Use the programs from problems 8-10.


What to Turn In

Turn in a single file hwk3.ss (or hwk3.scm) containing all code and documentation for this assignment. Make sure that both students' names are in a comment at the top of the file.


Hints and Guidelines


Back to the Assignments page