Blob


1 (define (test-case actual expected)
2 (newline)
3 (display "Actual: ")
4 (display actual)
5 (newline)
6 (display "Expected: ")
7 (display expected)
8 (newline))
10 (define (memq item x)
11 (cond ((null? x) false)
12 ((eq? item (car x)) x)
13 (else (memq item (cdr x)))))
14 (test-case (list 'a 'b 'c) '(a b c))
15 (test-case (list (list 'george)) '((george)))
16 (test-case (cdr '((x1 x2) (y1 y2))) '((y1 y2)))
17 (test-case (cadr '((x1 x2) (y1 y2))) '(y1 y2))
18 (test-case (pair? (car '(a short list))) #f)
19 (test-case (memq 'red '((red shoes) (blue socks))) #f)
20 (test-case (memq 'red '(red shoes blue socks)) '(red shoes blue socks))
22 Exercise 2.54. Two lists are said to be equal? if they contain equal elements arranged in the same order. For example,
24 (equal? '(this is a list) '(this is a list))
26 is true, but
28 (equal? '(this is a list) '(this (is a) list))
30 is false. To be more precise, we can define equal? recursively in terms of the basic eq? equality of symbols by saying that a and b are equal? if they are both symbols and the symbols are eq?, or if they are both lists such that (car a) is equal? to (car b) and (cdr a) is equal? to (cdr b). Using this idea, implement equal? as a procedure.36