1 12687dd9 2023-08-04 jrmu ;; The first three lines of this file were inserted by DrScheme. They record metadata
2 12687dd9 2023-08-04 jrmu ;; about the language level of this file in a form that our tools can easily process.
3 12687dd9 2023-08-04 jrmu #reader(lib "htdp-intermediate-reader.ss" "lang")((modname |37.3|) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp")))))
4 12687dd9 2023-08-04 jrmu ;A directory (dir) is a structure
5 12687dd9 2023-08-04 jrmu ;(make-dir name content size systems) where name, systems are symbols,
6 12687dd9 2023-08-04 jrmu ;size is a number, and content is a list-of-files-and-directories (LOFD).
8 12687dd9 2023-08-04 jrmu ;A list-of-files-and-directories (LOFD) is either
10 12687dd9 2023-08-04 jrmu ;2. (cons file lofd)
11 12687dd9 2023-08-04 jrmu ;3. (cons dir lofd),
12 12687dd9 2023-08-04 jrmu ;where file is a symbol, dir is a directory,
13 12687dd9 2023-08-04 jrmu ;and lofd is a LOFD (list-of-files-and-directories).
15 12687dd9 2023-08-04 jrmu (define-struct dir (name content size systems))
18 12687dd9 2023-08-04 jrmu ;fun-for-dir : dir -> ???
19 12687dd9 2023-08-04 jrmu ;(define (fun-for-dir a-dir)
20 12687dd9 2023-08-04 jrmu ; (... (dir-name a-dir) ...
21 12687dd9 2023-08-04 jrmu ; ... (fun-for-lofd (dir-content a-dir)) ...))
24 12687dd9 2023-08-04 jrmu ;fun-for-lofd : lofd -> ???
25 12687dd9 2023-08-04 jrmu ;(define (fun-for-lofd a-lofd)
27 12687dd9 2023-08-04 jrmu ; [(empty? a-lofd) ...]
28 12687dd9 2023-08-04 jrmu ; [(symbol? (first a-lofd)) ... (first a-lofd) ...
29 12687dd9 2023-08-04 jrmu ; ... (fun-for-lofd (rest a-lofd)) ...]
30 12687dd9 2023-08-04 jrmu ; [(dir? (first a-lofd)) ... (fun-for-dir (first a-lofd)) ...
31 12687dd9 2023-08-04 jrmu ; ... (fun-for-lofd (rest a-lofd)) ...]))
34 12687dd9 2023-08-04 jrmu (define Code (make-dir 'Code '(hang draw) 5 'ReadOnly))
35 12687dd9 2023-08-04 jrmu (define Docs (make-dir 'Docs '(read!) 5 'ReadWrite))
36 12687dd9 2023-08-04 jrmu (define Libs (make-dir 'Libs (list Code Docs) 5 'Executable))
37 12687dd9 2023-08-04 jrmu (define Text (make-dir 'Text '(part1 part2 part3) 5 'ReadOnly))
38 12687dd9 2023-08-04 jrmu (define TS (make-dir 'TS (list Text Libs 'read!) 5 'None))
40 12687dd9 2023-08-04 jrmu ;how-many : dir -> number
41 12687dd9 2023-08-04 jrmu ;Given a-dir, determine the number of
42 12687dd9 2023-08-04 jrmu ;files in the dir tree.
44 12687dd9 2023-08-04 jrmu (define (how-many a-dir)
45 12687dd9 2023-08-04 jrmu (how-many-lofd (dir-content a-dir)))
48 12687dd9 2023-08-04 jrmu ;how-many-lofd : lofd -> number
49 12687dd9 2023-08-04 jrmu ;Given a-lofd, determine the number of files
50 12687dd9 2023-08-04 jrmu ;in the lofd (search within subdirectories as well).
52 12687dd9 2023-08-04 jrmu (define (how-many-lofd a-lofd)
54 12687dd9 2023-08-04 jrmu [(empty? a-lofd) 0]
55 12687dd9 2023-08-04 jrmu [(symbol? (first a-lofd)) (+ 1
56 12687dd9 2023-08-04 jrmu (how-many-lofd (rest a-lofd)))]
57 12687dd9 2023-08-04 jrmu [(dir? (first a-lofd)) (+ (how-many (first a-lofd))
58 12687dd9 2023-08-04 jrmu (how-many-lofd (rest a-lofd)))]))