如何解决方案DrRacket中违反合同的错误?

问题描述 投票:0回答:1
(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而不是错误。

以下是绿名单的定义:绿名单是整数对的非空列表,其中整数对是正好是两个整数,每对‘(x y)都具有y – x = 1的属性。例如:‘((5 6)(3 4)(2 3)(-5 -4))是绿名单。

list scheme racket
1个回答
0
投票

由于条件顺序很重要]而导致错误。>。如果元素是一个元组,则应该测试first

© www.soinside.com 2019 - 2024. All rights reserved.