【发布时间】:2012-11-01 05:24:17
【问题描述】:
在 lisp 中是否有类似 find 的函数返回 true 而不是我们要查找的元素?
示例:
我希望它这样做
(find 'x '(a c x)) = t
不是
(find 'x '(a c x)) = x
另外,我问的原因是因为我试图到达列表中最深的元素。我的计划是每次递归调用它时都将列表展平。
然后我会停止递归调用
(mapcar 'atom list)
会告诉我那里的每个原子都是真实的。
你认为这是解决这个问题的好方法吗?
【问题讨论】:
-
为什么?在 lisp 中,除了 nil 之外的任何内容都是正确的。但是,双重否定会做你想做的事:即 (not (null (find ...)))