1 ;; The first three lines of this file were inserted by DrScheme. They record metadata
2 ;; about the language level of this file in a form that our tools can easily process.
3 #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")))))
6 ;A directory (dir) is either
8 ;2. (cons f dir) where f is a file
9 ;and dir is a directory, or
10 ;3. (cons dir1 dir2) where dir1, dir2
14 ;(define (fun-for-dir a-dir)
16 ; [(empty? a-dir) ...]
17 ; [(symbol? (first a-dir)) ... (first a-dir) ...
18 ; ... (fun-for-dir (rest a-dir)) ...]
19 ; [(cons? (first a-dir)) ... (first a-dir) ...
20 ; ... (fun-for-dir (rest a-dir)) ...]))
22 ;(define TS (cons 'read! (cons Text (cons Libs empty))))
23 ;(define Text (cons 'part1 (cons 'part2 (cons 'part3 empty))))
24 (define Docs '(read!))
25 (define Code '(hang draw))
26 (define Libs (list Code Docs))
27 (define Text '(part1 part2 part3))
28 (define TS (list 'read! Text Libs))
30 ;how-many : dir -> number
31 ;Given a-dir, determines the number of files
32 ;in the directory tree.
34 (define (how-many a-dir)
37 [(symbol? (first a-dir)) (+ 1
38 (how-many (rest a-dir)))]
39 [(cons? (first a-dir)) (+ (how-many (first a-dir))
40 (how-many (rest a-dir)))]))