New lab partners, new friends
It is time to switch lab partners! You may not work with a partner with whom you have previously worked this semester. Choose someone you haven't already worked with and relocate so that the two of you are sharing a single workstation.Switching pilot and co-pilot
In previous labs you were switching pair-programming roles in-between exercises. In this lab and in future labs, you will switch roles at regular intervals throughout the lab. The teaching assistants and tutors will announce that it is time to switch roughly every fifteen minutes.DR uber alles
Remember to practice using the design recipe for every problem!Don't Use IE
You will be unable to see the exercise numbers if you use IE.
As computer users we can create files and directories (sometimes called folders) on our computers to store our data and our programs. It is useful to have operations that allow manipulating these files and directories. Consider the following data definition of a flat FileSystem (FS), i.e., no directories, just files.
;; A File is a Symbol ;; An FS (FileSystem) is one of ;; -- empty ;; -- (cons File FS)
- Design a function called
totalthat consumes a FileSystemfsand produces the total number of files infs.
- Design a function that consumes a FileSystem and a File and returns
trueif the the file is present in the FileSystem andfalseotherwise.
Flat FileSystems quickly become chaotic. We would instead like to have a hierarchical way to structure our files on our machines. So we extend our previous data definition to accommodate for directories as well.
;; A File is a Symbol ;; A Dir is one of ;; -- empty ;; -- (cons File Dir) ;; -- (cons Dir Dir) ;; A Dir is constructed by gradually adding files and directories together: ;; - (cons f d) creates a directory adding file f to the contents of directory d ;; - (cons f (cons d empty)) creates a directory containing file f and subdirectory d ;; - (cons d1 d2) creates a directory adding subdirectory d1 to the contents of directory d2 ;; - (cons d1 (cons d2 empty)) creates a directory containing subdirectories d1 and d2
- Construct a Dir that represents the following directory tree:
- hw3.ss - hw1.ss + scratch - lists-and-recursion.ss - structs.ss - tetris.ss - syllabus.pdf + misc - olin.png - amal.png - r6rs.pdf - kitteh.png - hw2.ss
- Design a function that consumes a Dir
dand produces the total number of files in the whole directory tree ofd.
- Design a function that consumes a Dir
dand a Filefand returnstrueiffexists indor any of its subdirectories andfalseotherwise.
- Design a function that consumes a Dir
dand two Filessrcandtarget, and produces a Dir which has the same files asdbut with all files namedsrcrenamed totarget.
Directories gave us more structure but the information that we have for each file and directory is minimal. Let's add attributes to files and directories.
(define-struct file (name size owner)) ;; A File is (make-file Symbol Number Symbol) ;; (make-file s n o) creates a File with name s, size n kilobytes, and owned by o.For a directory we will split its contents into two pieces: one for a list of files and the other for a list of subdirectories.
;; An LoF (List-of-Files) is one of ;; -- empty ;; -- (cons File LoF) (define-struct dir (name dirs files)) ;; A Dir is a (make-dir Symbol LoD LoF) ;; (make-dir s ds fs) creates a Dir with name s containing ds as its list of ;; directories and fs as its list of files. ;; An LoD (List-of-Dir) is one of ;; -- empty ;; -- (cons Dir LoD)
- Design a function that consumes a Dir
dand produces the total number of files (just files, not directories) in the directory tree ofd.
- Design a function that consumes a Dir
dand a Symbolsrepresenting an owner and returns a list of files owned bysin the directory tree ofd.
- Design a function that consumes a Dir
dand a Numbernrepresenting file size and returns a list of files in the directory tree ofdwith size greater or equal ton.
- Design a function that consumes a Dir
dand computes the total size of all files in the whole directory tree. You may assume that directories take up no space.If you finish early, try tweaking the code to better understand what was given. Enjoy!