;; The first three lines of this file were inserted by DrScheme. They record metadata ;; about the language level of this file in a form that our tools can easily process. #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"))))) (define list-a (list 0 1 2 3 4 5)) (define list-b (cons 0 (cons 1 (cons 2 (cons 3 (cons 4 (cons 5 empty))))))) (define list-c (list (list 'adam 0) (list 'eve 1) (list 'louisXIV 2))) (define list-d (cons (cons 'adam (cons 0 empty)) (cons (cons 'eve (cons 1 empty)) (cons (cons 'louisXIV (cons 2 empty)) empty)))) ;Data Definition ;A mixed-list is either ;1. an empty list ;2. (cons ns ml) where ns is either a number or a symbol ;and ml is a mixed-list ;3. (cons ml1 ml2) where ml1 and ml2 are both mixed-lists. ; ; ; ;list=? : mixed-list mixed-list -> boolean ;Compares list1 and list2 and returns true if equal, ;false otherwise. (define (list=? list1 list2) (cond [(and (empty? list1) (empty? list2)) true] [(or (empty? list1) (empty? list2)) false] [(and (symbol? (first list1)) (symbol? (first list2)) (symbol=? (first list1) (first list2))) (list=? (rest list1) (rest list2))] [(and (number? (first list1)) (number? (first list2)) (= (first list1) (first list2))) (list=? (rest list1) (rest list2))] [(and (cons? (first list1)) (cons? (first list2)) (list=? (first list1) (first list2))) (list=? (rest list1) (rest list2))] [else false])) (define list-e (cons (cons 1 (cons 2 empty)) empty)) (define list-f (list (list 1 2))) ;(list=? list-g list-h) is incorrect for this case (define list-g (cons 'a (cons (cons 1 empty) (cons false empty)))) (define list-h (list 'a (cons 1 empty) false)) (cons (cons 1 (cons 2 empty)) (cons (cons 2 (cons 3 empty)) empty)) (list (list 1 2) (list 2 3)) (cons 'a (list 0 false)) (cons 'a (cons 0 (cons false empty))) (list 'a 0 false) (list (cons 1 (cons 13 empty))) (cons (cons 1 (cons 13 empty)) empty) (list (list 1 13)) (list empty empty (cons 1 empty)) (cons empty (cons empty (cons (cons 1 empty) empty))) (list empty empty (list 1)) (cons 'a (cons (list 1) (list false empty))) (cons 'a (cons (cons 1 empty) (cons false (cons empty empty)))) (list 'a (list 1) false empty) (list (symbol=? 'a 'b) (symbol=? 'c 'c) false) (list false true false) (cons false (cons true (cons false empty))) (list (+ 10 20) (* 10 20) (/ 10 20)) (list 30 200 0.5) (cons 30 (cons 200 (cons 0.5))) (list 'dana 'jane 'mary 'laura) (cons 'dana (cons 'jane (cons 'mary (cons 'laura)))) (first (list 1 2 3)) 1 (rest (list 1 2 3)) (list 2 3) (cons 2 (cons 3 empty)) '(1 a 2 b 3 c) (list 1 'a 2 'b 3 'c) '((alan 1000) (barb 2000) (carl 1500) (dawn 2300)) (list (list 'alan 1000) (list 'barb 2000) (list 'carl 1500) (list 'dawn 2300)) '((My First Paper) (Sean Fisler) (Section 1 (Subsection 1 Life is difficult) (Subsection 2 But learning things makes it interesting)) (Section 2 Conclusion? What conclusion?)) (list (list 'My 'First 'Paper) (list 'Sean 'Fisler) (list 'Section 1 (list 'Subsection 1 'Life 'is 'difficult) (list 'Subsection 2 'But 'learning 'things 'makes 'it 'interesting)) (list 'Section 2 (list 'Conclusion? 'What 'conclusion?))