;; file: hw1pr1.rkt ;; submission site id: ;; time spent: ;; other comments? #lang racket (require htdp/testing) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Function 0 ;; one possible example of appropriate commenting ;; and testing... ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; len ;; inputs: L, a list of any items ;; output: the number of top-level items in the input list (define (len L) (if (null? L) 0 (+ 1 (len (rest L))))) ; provided tests (check-expect (len '()) 0) (check-expect (len '(s p a m)) 4) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Function 1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; remove-all ;; inputs: ;; output: (define (remove-all e L) 0) ;; empty until implemented! ; provided tests (check-expect (remove-all "i" '("a" "l" "i" "i" "i" "e" "n")) '("a" "l" "e" "n")) (check-expect (remove-all "i" '( ("a" "l" "i") "i" "i" "e" "n")) '(("a" "l" "i") "e" "n")) (check-expect (remove-all 0 '(1 0 1 0 1 0)) '(1 1 1)) ; additional tests ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Function 2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; prefix ;; inputs: ;; output: (define (prefix? P L) 0) ; provided tests (check-expect (prefix? '() '(s p a m)) #t) (check-expect (prefix? '(s p) '(s p a m)) #t) (check-expect (prefix? '(s m) '(s p a m)) #f) (check-expect (prefix? '(p a) '(s p a m)) #f) ; additional tests ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Function 3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; sublist ;; inputs: ;; output: (define (sublist? S L) 0) ; provided tests (check-expect (sublist? '() '(s p a m)) #t) (check-expect (sublist? '(s p) '(s p a m)) #t) (check-expect (sublist? '(s m) '(s p a m)) #f) (check-expect (sublist? '(p a) '(s p a m)) #t) (check-expect (sublist? '(a b c) '(b a b a c)) #f) (check-expect (sublist? '(a b c) '(b a b c c)) #t) ; additional tests ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Function 4 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; enumerate ;; inputs: ;; output: (define (enumerate L) 0) ; provided tests (check-expect (enumerate '(jan feb mar apr)) '((0 jan) (1 feb) (2 mar) (3 apr))) (check-expect (enumerate '(0 I II III IV V VI)) '((0 0) (1 I) (2 II) (3 III) (4 IV) (5 V) (6 VI))) (check-expect (enumerate '()) '()) ; additional tests ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (generate-report)