Filesystem
1 Core Assignment
Please read Chapter 16 of How to Design Programs (HtDP). Complete exercises 16.3.2-16.3.4 and the Challenge question.
2 Clarifications
Please do the assignment in Pyret, not Racket!
Though we would love to see your response for the follow-up question for 16.3.2, we aren’t requiring you to.
There is a solution attached to 16.3.2. Though you can of course read it we suggest you don’t, at least not until you’ve completed the problem.
Because you will be doing this in Pyret, not Racket, you can’t run this directly on your own filesystem.
In the second part of exercise 16.3.3, the size of a directory is the sum of the sizes of its contents, the length of its files list, and the length of its dirs list. For example, in HtDP Figure 44, the size of the “TS” directory is 218, and the size of the “Code” directory is 12.
The assignment talks about “symbols”, which Pyret doesn’t have. Please use strings instead of symbols. Thus, all names are strings.
Exercise 16.3.4 asks you to implement a function find? but ? is not a valid character for an identifier in Pyret. Therefore, please name this function can-find instead.
You may not use any List or Set functions found in the documentation. This includes higher-order functions like map (if you know what those are).
You may use == to check whether one String is equal to another, but no other String functions.
We’ve noticed that some of you are using nested functions (i.e., one function written inside another), and when you do, you seem to ignore all the steps of the design recipe for those inner functions. Note that nesting functions is not an excuse for skimping on the recipe, and you’ll be penalized if you do.
The Challenge question asks you to “Generalize the function [find] to return a list of paths if the file name occurs more than once. Each path should lead to a different occurrence, and there should be a path for each occurrence.” Because Pyret has a built-in function called find, we ask you to name this function fynd instead. The fynd function you hand in should have the header
fun fynd(d :: Dir, name :: String) -> List<Path>:
where a path is a list of names. Note: it should return empty if the file name does not occur (rather than false as stated under the challenge instructions), and a list containing a single path if the file name occurs only once.
Within a single directory, all the names must be unique.
3 Files
4 Handing In
Please use the filename file-system.arr. (Please note the name carefully.)