【发布时间】:2015-05-04 12:27:06
【问题描述】:
我正在尝试在方案中定义一个过滤数字流的函数。我的函数将接受一个数字 num 和一个 stream s,并过滤掉 num 是流中数字的一个因子。
我的代码目前如下所示:
(define filter$
(lambda (num s)
(if (or (= num 0)(null? s))
'()
(if (= (modulo (car s) num) 0)
(filter$ num (cdr s))
(cons (car s) (filter$ num (cdr s)))))))
我目前收到一个错误:
car: contract violation
expected: pair?
given: #<procedure:... saved location of file/location of the error>
我正在为此在 Racket 工作(特别是 DrRacket),这是学校的工作。我希望在了解导致此错误的原因以及我能做些什么来修复它方面获得帮助。
【问题讨论】:
-
您传递给
filter$的哪些参数会产生此错误?
标签: filter stream scheme racket