我对Lisp还比较陌生,试图解决找到两个列表的差异的问题。需要在列表2中找到所有不在列表1中的数字。
希望得到(diff list1 list2)
...例如:(diff '(4 5 6 8 9) '(1 2 4 6 8 9))
返回结果为(1 2)
目前我已经有了:
(defun diff (l1 l2)
(cond ((null l1) nil)
((member (first l1) l2) (diff(rest l1) l2))
(t (cons (first l2) (diff (rest l2) l1)))))
(defun diff1 (l1 l2)
(cond ((null l1) nil)
((member (first l2) l1) (diff (rest l2) l1))
(t (cons (first l2) (diff (rest l2) l1)))))
我尝试过两种不同的方法,但似乎无法让其返回List 2而非List 1。