【发布时间】:2017-03-12 18:40:11
【问题描述】:
因此,我的任务是创建一个程序,该程序为您提供两个字母和一个列表,需要在该列表中找到它们。我开始编写程序,但很快就发现了一些错误。我的代码如下:
(define (count-2-consecutive x y lst)
(define (iter ctr lst)
(cond ((null? lst) '())
((and (eq? x (car lst)) (eq? y (cadr lst))) (count-2-consecutive x y (cdr lst)))
(else (count-2-consecutive x y (cdr lst)))))
(iter 0 lst))
因此,当我尝试运行示例时(例如:(count-2-consecutive 'n 't '(h o t t e n t o t t e n t e n t e n)) 我收到“违反合同”错误,指向我在代码中使用的cadr。如果有人可以帮助我指出什么我做错了,非常感谢。
【问题讨论】:
标签: list recursion scheme iteration racket