0

我是 LISP 的初学者。我在 lisp 中使用clispubuntu我在 lisp 中有一个代码来对两个列表执行联合操作。逻辑是正确的。但是遇到了一个错误:

*** - APPEND: A proper list must not end with T

我的代码是:

(defun set-union (L1 L2)
(cond 
 ((null L2)   ;if l2 is null then union is l1 itself. 
  L1) 
 ((not (member (first L2) L1))  ;check if first member of l2 is in l1 or not
  (setq l1 (append (set-union L1 (rest L2)) (list (first L2))))) ;if not then append it with the union of l1 and rest of l2.
 (t
  (set-union L1 (rest L2)))
  )) ;if second condition is not true then carry out union on l1 and rest of the elements of l2
(setq l1 (list 'a 'c 'b 'g))
(setq l2 (list 'd 'g 't))
(set-union l1 l2)
(print l1)

我需要帮助!谢谢。

4

1 回答 1

1
(append (set-union L1 (rest L2)) (first L2))

在您的逻辑的某个时刻尝试附加(ACBG . T) 和 E,但由于第一个不是正确的列表而失败。

要么使用

(append (set-union L1 (rest L2)) (list (first L2)))

或更好

(cons (first L2) (set-union L1 (rest L2)))
于 2015-10-31T05:43:11.723 回答