Common-Lisp中`find`函数的异常行为

dav*_*ugh 3 search common-lisp

在搜索nil序列中的使用find总是返回NIL

(find nil #(a b nil c)) -> NIL

(find nil #(a b c)) -> NIL
Run Code Online (Sandbox Code Playgroud)

如果序列是列表,则相同。

但是,member运行符合我的预期:

(member nil '(a b nil c)) -> (NIL C)
Run Code Online (Sandbox Code Playgroud)

为什么find设计为以这种方式运行?

请注意,它的position工作与我期望的一样:

(position nil #(a b nil c)) -> 2

(position nil #(a b c)) -> NIL
Run Code Online (Sandbox Code Playgroud)

Xac*_*ach 7

如果目标元素为NIL,则FIND根本没有用。它返回找到的元素,但与未发现的情况没有区别。如果您想找出序列中没有nil,则POSITION是一个更好的选择。还有许多其他选择。