首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Lisp:执行set联合操作

Lisp:执行set联合操作
EN

Stack Overflow用户
提问于 2015-10-31 03:38:40
回答 1查看 467关注 0票数 0

我是lisp的初学者。我使用clisp in ubuntu.I,在lisp中有一个代码在lisp上执行联合操作,lists.The逻辑是correct.But卡在一个错误上的,这是:

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

我的代码是:

代码语言:javascript
复制
(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)

我需要帮助!!谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-10-31 05:43:11

代码语言:javascript
复制
(append (set-union L1 (rest L2)) (first L2))

在某种程度上,你的逻辑试图追加 (A,C,B,G)。和E,因为第一个不是正确的列表而失败。

要么使用

代码语言:javascript
复制
(append (set-union L1 (rest L2)) (list (first L2)))

或者更好

代码语言:javascript
复制
(cons (first L2) (set-union L1 (rest L2)))
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33447794

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档