gpt4 book ai didi

lisp - 从列表中删除原子的出现 - LISP

转载 作者:太空宇宙 更新时间:2023-11-03 18:54:24 25 4
gpt4 key购买 nike

我是 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com