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 13.0.3) (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))))
13 ;A mixed-list is either
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.
21 ;list=? : mixed-list mixed-list -> boolean
22 ;Compares list1 and list2 and returns true if equal,
25 (define (list=? list1 list2)
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))]
44 (list=? (first list1) (first list2)))
45 (list=? (rest list1) (rest list2))]
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
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))
61 (cons 'a (list 0 false))
62 (cons 'a (cons 0 (cons false empty)))
65 (list (cons 1 (cons 13 empty)))
66 (cons (cons 1 (cons 13 empty)) empty)
69 (list empty empty (cons 1 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)