「Little Schemer」の本を読んで、さまざまな機能を実行しています。通常、本と同じバージョンになりますが、2 つのリストの等価性をテストする関数である eqlist? についてはそうではありません。
私は自分のバージョンをテストしようとしましたが、私が投げたものは何でも通過します。それでも、「Little Schemer」バージョンとは少し異なります。また、何かが欠けているかどうかについて誰かの意見が欲しいです。
私のバージョン:
(define eqlist?
(lambda (list1 list2)
(cond
((and (null? list1)(null? list2))#t)
((or (null? list1)(null? list2))#f)
((and (atom? list1)(atom? list2))(eqan? list1 list2))
((or (atom? list1)(atom? list2)) #f)
(else
(and(eqlist? (car list1) (car list2))
(eqlist? (cdr list1) (cdr list2)))))))
本のバージョン:
(define eqlist2? ;This is Little Schemer's version
(lambda (list1 list2)
(cond
((and (null? list1)(null? list2)) #t)
((or (null? list1)(null? list2)) #f)
((and (atom? (car list1))(atom? (car list2)))
(and (eqan? (car list1)(car list2))(eqlist2? (cdr list1)(cdr list2))))
((or (atom? (car list1))(atom? (car list2))) #f)
(else
(and (eqlist2? (car list1)(car list2))
(eqlist2? (cdr list1)(cdr list2)))))))
どちらの場合も、eqan の定義は次のとおりです。
(define eqan?
(lambda (a1 a2)
(cond
((and (number? a1)(number? a2)) (equal? a1 a2))
((or (number? a1)(number? a2)) #f)
(else (eq? a1 a2)))))
ありがとうございました!
ジョス・ドラージ