我在递归方面遇到了麻烦。我这里的程序很简单。它消耗一个捐赠列表,如果列表中的任何捐赠超过 2500,则返回 true。
(define-struct donation (donor amount))
这是我的帮手
;;helper
(define (bad-donations bad-d)
(cond
[(number? bad-d) (<= 50 bad-d)]
[(donation? bad-d) (< 2500 (donation-amount bad-d))]))
(check-expect (bad-donations 51) true)
(check-expect (bad-donations 30) false )
(check-expect (bad-donations 50) true)
(define (any-bad-donations? lod)
(cond
[(empty? lod) true]
[(cons? lod)
(bad-donations (first lod))]
[else
(any-bad-donations? (bad-donations (rest lod)))]))
如果我做类似的事情,它工作正常
(any-bad-donations? (list (make-donation "Marry" 50000))
应该会产生 True,因为它超过了 2500 的限制。
但如果我这样做
(any-bad-donations? (list (make-donation "Marry" 50) (make-donation "Marry 50000))
它会给我 False,它不应该,因为其余的超过 2500。所以它应该给我真实的。
我在程序的递归部分做错了什么?