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.
我可以写一个这样的函数
(define (bool-num x) (if x 1 0)) (define (cnt-true lst) (foldl + 0 (map bool-num lst)))
但我发现并不优雅,因为球拍有一个count功能 and false?,但没有true?
count
false?
true?
所以我可以计算错误元素的数量:
(count false? lst)
有什么我想念的吗?
您正在寻找程序identity:
identity
(count identity '(#t #f #t #t #f)) => 3 (count identity '(1 2 #t #f #f 9)) => 4