方案二列出了交集

时间:2017-01-26 08:22:46

标签: functional-programming scheme

我已经写了这段代码

(define (in-list? val ls)
  (if (null? ls) #f 
    (if 
        (= (car ls) val) #t
        (in-list? val (cdr ls))
    )
  )
)
(define (intersect ls1 ls2)
  (if (null? ls1)
    '()
    (if (in-list? (car ls1) ls2) 
        (cons (car ls1) (intersect (cdr ls1) ls2))
        (intersect (cdr ls1) ls2)
    )
  )
)

如果我问(相交'(1 2 3)'(1 4 7))它正常工作但是当我尝试时它返回空列表(相交'(abc)&#39 ;(ABD))

0 个答案:

没有答案