Blob


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 14.1.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 (define list-a (list 0 1 2 3 4 5))
5 (define list-b (cons 0 (cons 1 (cons 2 (cons 3 (cons 4 (cons 5 empty)))))))
6 (define list-c (list (list 'adam 0) (list 'eve 1) (list 'louisXIV 2)))
7 (define list-d (cons (cons 'adam (cons 0 empty))
8 (cons (cons 'eve (cons 1 empty))
9 (cons (cons 'louisXIV (cons 2 empty)) empty))))
12 ;Data Definition
13 ;A mixed-list is either
14 ;1. an empty list
15 ;2. (cons ns ml) where ns is either a number or a symbol
16 ;and ml is a mixed-list
17 ;3. (cons ml1 ml2) where ml1 and ml2 are both mixed-lists.
18 ;
19 ;
20 ;
21 ;list=? : mixed-list mixed-list -> boolean
22 ;Compares list1 and list2 and returns true if equal,
23 ;false otherwise.
25 (define (list=? list1 list2)
26 (cond
27 [(and
28 (empty? list1)
29 (empty? list2)) true]
30 [(or
31 (empty? list1)
32 (empty? list2)) false]
33 [(and (symbol? (first list1))
34 (symbol? (first list2))
35 (symbol=? (first list1) (first list2)))
36 (list=? (rest list1) (rest list2))]
37 [(and (number? (first list1))
38 (number? (first list2))
39 (= (first list1) (first list2)))
40 (list=? (rest list1) (rest list2))]
41 [(and
42 (cons? (first list1))
43 (cons? (first list2))
44 (list=? (first list1) (first list2)))
45 (list=? (rest list1) (rest list2))]
46 [else false]))
48 (define list-e (cons (cons 1 (cons 2 empty)) empty))
49 (define list-f (list (list 1 2)))
50 ;(list=? list-g list-h) is incorrect for this case
51 (define list-g (cons 'a
52 (cons (cons 1 empty)
53 (cons false empty))))
54 (define list-h (list 'a (cons 1 empty) false))
56 (cons (cons 1 (cons 2 empty))
57 (cons (cons 2 (cons 3 empty)) empty))
58 (list (list 1 2)
59 (list 2 3))
61 (cons 'a (list 0 false))
62 (cons 'a (cons 0 (cons false empty)))
63 (list 'a 0 false)
65 (list (cons 1 (cons 13 empty)))
66 (cons (cons 1 (cons 13 empty)) empty)
67 (list (list 1 13))
69 (list empty empty (cons 1 empty))
70 (cons empty
71 (cons empty
72 (cons (cons 1 empty) empty)))
73 (list empty empty (list 1))
75 (cons 'a (cons (list 1) (list false empty)))
76 (cons 'a (cons (cons 1 empty) (cons false (cons empty empty))))
77 (list 'a (list 1) false empty)
79 (list (symbol=? 'a 'b) (symbol=? 'c 'c) false)
80 (list false true false)
81 (cons false
82 (cons true
83 (cons false empty)))
85 (list (+ 10 20) (* 10 20) (/ 10 20))
86 (list 30 200 0.5)
87 (cons 30
88 (cons 200
89 (cons 0.5)))
91 (list 'dana 'jane 'mary 'laura)
92 (cons 'dana
93 (cons 'jane
94 (cons 'mary
95 (cons 'laura))))
97 (first (list 1 2 3))
98 1
99 (rest (list 1 2 3))
100 (list 2 3)
101 (cons 2 (cons 3 empty))
103 '(1 a 2 b 3 c)
104 (list 1 'a 2 'b 3 'c)
106 '((alan 1000)
107 (barb 2000)
108 (carl 1500)
109 (dawn 2300))
110 (list (list 'alan 1000)
111 (list 'barb 2000)
112 (list 'carl 1500)
113 (list 'dawn 2300))
115 '((My First Paper)
116 (Sean Fisler)
117 (Section 1
118 (Subsection 1 Life is difficult)
119 (Subsection 2 But learning things makes it interesting))
120 (Section 2
121 Conclusion? What conclusion?))
122 (list (list 'My 'First 'Paper)
123 (list 'Sean 'Fisler)
124 (list 'Section 1
125 (list 'Subsection 1 'Life 'is 'difficult)
126 (list 'Subsection 2 'But 'learning 'things 'makes 'it 'interesting))
127 (list 'Section 2
128 (list 'Conclusion? 'What 'conclusion?))