我是 LISP 的新手,在这里我试图从列表中删除所有出现的原子 -
到目前为止我的代码 -
(defun rematom (A LAT)
(cond
((null LAT) ())
((EQ (car LAT) A car LAT))
(T (cons (car LAT)(rematom, A (cdr LAT))))
)))
此代码正在删除第一次出现的元素,如何删除所有出现的元素?
我的输出 -
> (rematom 'a '(a b c a d a))
(B C A D A)
期望-
>(rematom 'a '(a b c a d a))
(B C D)
谢谢。
最佳答案
第二种情况应该调用rematom:
((EQ (car LAT) A) (rematom A (cdr LAT)))
只有第一种情况,即检查空列表的基本情况,应该是非递归的。这里其他的需要递归调用rematom。
关于lisp - 从列表中删除原子的出现 - LISP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48133990/