0
我在不同的平臺上遇到了一些問題。 這是我的代碼:Liitle Schemer 4th page103 value function
(define o+
(lambda (n m)
(cond
((zero? n) m)
(else (o+ (sub1 n) (add1 m))))))
(define value
(lambda (nexp)
(cond
((atom? nexp) nexp)
((eq? (car (cdr nexp)) 'o+)
(o+ (value (car nexp))
(value (car (cdr (cdr nexp))))))
((eq? (car (cdr nexp)) 'o-)
(o- (value (car nexp))
(value (car (cdr (cdr nexp))))))
((eq? (car (cdr nexp)) 'o*)
(o* (value (car nexp))
(value (car (cdr (cdr nexp))))))
((eq? (car (cdr nexp)) 'o/)
(o/ (value (car nexp))
(value (car (cdr (cdr nexp)))))))))
雞方案:
(value '(1 o+ 1)) => 2
麻省理工學院的方案:
(value '(1 o+ 1)) => ;Unspecified return value
爲什麼?它讓我困惑。
atom?是非標準的。原子的定義是什麼?在MIT? – user448810