【发布时间】:2020-06-16 20:52:35
【问题描述】:
(define is1?
(lambda (tuple)
(if (and (= 2 (length tuple))
(= 1 (- (cadr tuple) (car tuple)))
(list? tuple))
#t
#f)))
(define greenlist?
(lambda (x) (andmap is1? x)))
(greenlist? '((2 4 6) (5 6) (1 2)))
(greenlist? '(3 4 5 6))
第二个命令:(greenlist? '(3 4 5 6)) 在应该返回 false 时返回错误。
相反,我得到了这个错误:
长度:违反合同
预期:列表?
给定:3
我应该在我的代码中进行哪些更改以使其返回 false 而不是错误?
这是绿名单的定义:
绿色列表是整数对的非空列表,其中一对 integers 是正好两个整数的列表,其中每一对
'( x y)具有 y – x = 1 的属性。例如:
'((5 6) (3 4) (2 3) (-5 -4))是绿名单。
【问题讨论】:
-
请使用能够正确缩进代码的编辑器,您不应该只使用右括号编写行。看我的回答,这是在 Scheme 中格式化代码的正确方法。
-
感谢您告诉我。