到第32页(第四版 电子工业出版社)
1、书中定义的函数
1)检查是否为原子:
(define atom?
(
lambda(x)
(and (not (pair? x)) (not (null? x)))))
2)检查列表元素是否全部为原子:
(define lat?
(lambda(l)
(cond
((null? l)#t)
((atom? (car l))(lat? (cdr l)))
(else #f))))
3)检查原子是不是列表的成员:
(define member?
(lambda(a lat)
(cond
((null? lat)#f)
(else(or(eq? (car lat)a)
(member? a(cdr lat)))))))
2、一些内建的方法:
1)car:取得点对的第一个元素
2)cdr:取得点对的第二个元素
3)cons:构造点对
4)null?:判断列表是否为空,是则返回#t
5)eq?:判断两元素是否相等,是则返回#t
注意:car返回的是列表中的第一个原子,而cdr总会得到一个(除去了第一个原子的)列表,在书里有一个例子:
(eq?(cdr l)a)是真是假,其中l是(soured milk),a是milk。答案是没有答案,原因是(cdr l)得到的是(milk),是一个列表,而另一个比较对象是原子。然而在racket里。。。。