SICP_2.53-2.55

 1 #lang racket
 2 
 3 ;;;;;;;;;;;;;;;;;;2.53
 4 (define (memq item x)
 5   (cond ((null? x) false)
 6         ((eq? item (car x)) x)
 7         (else (memq item (cdr x)))))
 8 
 9 (list 'a 'b 'c)
10 
11 (list (list 'george))
12 
13 (cdr '((x1 x2) (y1 y2)))
14 
15 (cadr '((x1 x2) (y1 y2)))
16 
17 (pair? (car '(a short list)))
18 
19 (memq 'red '((red shoes) (blue socks)))
20 
21 (memq 'red '(red shoes blue socks))
22 
23 ;;;;;;;;;;;;;;;2.54
24 (define (equal? a b)
25   (cond ((and (pair? a) (pair? b)
26               (equal? (car a) (car b))
27               (equal? (cdr a) (cdr b)))
28          true)
29         ((eq? a b) true)
30         (else false)))
31 
32 ;;;;;;;;;;;;;test
33 (equal? '(this is a list) '(this is a list))
34 
35 (equal? '(this is a list) '(this (is a) list))
36 
37 ;;;;;;;;;;;;;;2.55
38 (car ''abracadara)
39 
40 (car '(quoto abracadara))

"  ' " 相当于是单引号,只不过省略了后半引号

posted @ 2017-02-24 20:37  lan126  阅读(207)  评论(0编辑  收藏  举报