;; The define-structs for the two types of files: ;; (define-struct simple (name contents)) (define-struct dir (name files)) ; ; As per data defn, ; is a symbol in both cases; ; is a list-of-symbol, and ; is a list-of-file. ;; First some small examples, to which we attach placeholders. ;; (define hw1-file1 (make-simple 'hw1-problem1.ss (cons 'silly (cons 'contents empty)))) (define hw1-file2 (make-simple 'hw1-problem2.ss (cons 'sillier (cons 'contents empty)))) (define hw1-files (cons hw1-file1 (cons hw1-file2 empty))) (define hw1-dir (make-dir 'hw1 hw1-files)) ; Can you make a directory that contains hw1-dir ? ;; Okay, now a large example: ;; (define hw2-dir (make-dir 'hw2 (list (make-simple 'hw2.ss (list 'no 'problem)) (make-simple 'hw2-first-try (list 'i 'love 'comp)) (make-simple 'therapy (list 'meets 'at 'noon)) (make-simple 'hw2-test.ss (list 'some 'sample 'inputs))))) (define ians-dir (make-dir 'ian (list (make-simple 'Readme (list 'My 'home 'directory)) (make-simple 'love (list 'i 'am 'no 'good 'at 'tennis)) (make-dir 'comp210 (list hw1-dir (make-simple 'README-210 (list 'hi)) hw2-dir (make-simple 'myLabTime (list 'tue '14:00)))) (make-simple 'grocery-list (list 'beer 'and 'a 'love 'of 'bread)) (make-dir 'mail (list (make-simple 'msg1 (list 'hi 'mom 'dad 'please 'send 'money 'love 'your 'child)) (make-simple 'msg2 (list 'no 'way 'love 'your 'parents)) (make-simple 'msg3 (list 'no 'prob 'i 'am 'selling 'platelets)) (make-simple 'msg4 (list 'wait 'check 'is 'in 'the 'mail)))) (make-simple 'doveLetter (list 'come 'back 'i 'love 'you 'my 'lost 'homing 'pigeon))))) ;;;;;;;;;;;;;;;;; Some tests (not meant to be comprehensive!) (grep 'silly hw1-file1) = #t (grep 'silly hw1-file2) = #f (grep 'silly hw1-dir) = #f ; grep doesn't descend into dirs. (grep* 'silly empty) = #f (grep* 'silly hw1-files) = #t (grep* 'hate (dir-files ians-dir)) = #f (grep* 'platelets (dir-files ians-dir)) = #f ; grep* doesn't descend into dirs. (grepr* 'platelets ians-dir) = #t (grepr* 'Readme ians-dir) = #f ; grepr* matches file content, not name.