今天回到屋子先睡了一觉,昨天没休息好,打了一宿蚊子,战果丰盛。睡醒后,开始,找一些好听的音乐。最后该看书了,继续我的The Little Scheme。本来,我是先看SICP的,但是,看着看着不知怎么就跑到这本书了。还好这本比较薄,马上就要看完了。接下来,写了几个习题:
用Scheme写程序就是一个字:爽。
比较两个list相等:
(define atom?
(lambda (x)
(not (or (null? x) (pair? x)))))
(define insertR*
(lambda (old new lat)
(cond
((null? lat) '())
((atom? (car lat))
(cond
((eq? old (car lat))
(cons (car lat) (cons new (insertR* old new (cdr lat)))))
(else (cons (car lat) (insertR* old new (cdr lat))))))
(else
(cons (insertR* old new (car lat)) (insertR* old new (cdr lat)))))))
用Scheme写程序就是一个字:爽。
比较两个list相等:
(define eqlist*
(lambda (lat1 lat2)
(cond
((and (null? lat1) (null? lat2)) #t)
((or (null? lat1) (null? lat2)) #f)
((and (atom? (car lat1)) (atom? (car lat2))) (and (eq? (car lat1) (car lat2)) (eqlist* (cdr lat1) (cdr lat2))))
(else (and (eqlist* (car lat1) (car lat2)) (eqlist* (cdr lat1) (cdr lat2)))))))