Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我无法理解 Scheme 如何形成然后检测列表。它如何确定列表和点对之间的区别?
列表结构由对形成。一个正确的列表是一个对链,其中最后一个对有一个空列表作为它的cdr.. 我们可以list?这样:
cdr
list?
(define (list? lst) (cond ((null? lst) #t) ((pair? lst) (list? (cdr lst))) (else #f)))
或者您可以使用和/或:
(define (list? lst) (or (null? lst) (and (pair? lst) (list? (cdr lst)))))