Blame


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 16.2.1) (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 file is a symbol.
5 12687dd9 2023-08-04 jrmu ;
6 12687dd9 2023-08-04 jrmu ;A directory (dir) is either
7 12687dd9 2023-08-04 jrmu ;1. empty,
8 12687dd9 2023-08-04 jrmu ;2. (cons f dir) where f is a file
9 12687dd9 2023-08-04 jrmu ;and dir is a directory, or
10 12687dd9 2023-08-04 jrmu ;3. (cons dir1 dir2) where dir1, dir2
11 12687dd9 2023-08-04 jrmu ;are directories.
12 12687dd9 2023-08-04 jrmu
13 12687dd9 2023-08-04 jrmu ;Template
14 12687dd9 2023-08-04 jrmu ;(define (fun-for-dir a-dir)
15 12687dd9 2023-08-04 jrmu ; (cond
16 12687dd9 2023-08-04 jrmu ; [(empty? a-dir) ...]
17 12687dd9 2023-08-04 jrmu ; [(symbol? (first a-dir)) ... (first a-dir) ...
18 12687dd9 2023-08-04 jrmu ; ... (fun-for-dir (rest a-dir)) ...]
19 12687dd9 2023-08-04 jrmu ; [(cons? (first a-dir)) ... (first a-dir) ...
20 12687dd9 2023-08-04 jrmu ; ... (fun-for-dir (rest a-dir)) ...]))
21 12687dd9 2023-08-04 jrmu
22 12687dd9 2023-08-04 jrmu ;(define TS (cons 'read! (cons Text (cons Libs empty))))
23 12687dd9 2023-08-04 jrmu ;(define Text (cons 'part1 (cons 'part2 (cons 'part3 empty))))
24 12687dd9 2023-08-04 jrmu (define Docs '(read!))
25 12687dd9 2023-08-04 jrmu (define Code '(hang draw))
26 12687dd9 2023-08-04 jrmu (define Libs (list Code Docs))
27 12687dd9 2023-08-04 jrmu (define Text '(part1 part2 part3))
28 12687dd9 2023-08-04 jrmu (define TS (list 'read! Text Libs))
29 12687dd9 2023-08-04 jrmu
30 12687dd9 2023-08-04 jrmu ;how-many : dir -> number
31 12687dd9 2023-08-04 jrmu ;Given a-dir, determines the number of files
32 12687dd9 2023-08-04 jrmu ;in the directory tree.
33 12687dd9 2023-08-04 jrmu
34 12687dd9 2023-08-04 jrmu (define (how-many a-dir)
35 12687dd9 2023-08-04 jrmu (cond
36 12687dd9 2023-08-04 jrmu [(empty? a-dir) 0]
37 12687dd9 2023-08-04 jrmu [(symbol? (first a-dir)) (+ 1
38 12687dd9 2023-08-04 jrmu (how-many (rest a-dir)))]
39 12687dd9 2023-08-04 jrmu [(cons? (first a-dir)) (+ (how-many (first a-dir))
40 12687dd9 2023-08-04 jrmu (how-many (rest a-dir)))]))