assoc 只是 find 的语法糖吗?

joh*_*ers 1 lisp common-lisp

CL-USER> *mylist*
((RED . 5) (RED . 4) (RED . 3) (BLUE . 5) (RED . 2) (BLUE . 4))
CL-USER> (assoc 'blue *mylist*)
(BLUE . 5)
CL-USER> (find 'blue *mylist* :key #'car)
(BLUE . 5)
Run Code Online (Sandbox Code Playgroud)

在我看来,这assoc只是 的一个特例find,这是真的还是我错过了一些assoc在这里不明显的额外功能?

Lar*_*off 5

clhs.lisp.se/Body/f_assocc.htm

两种表达

(assoc item list :test fn)
Run Code Online (Sandbox Code Playgroud)

(find item list :test fn :key #'car)
Run Code Online (Sandbox Code Playgroud)

意思是等价的,但有一个例外:如果 nil 出现在 alist 中代替一对,并且 item 为 nil,find 将计算 alist 中 nil 的汽车,发现它等于 item,并返回 nil,而 assoc 将忽略 alist 中的 nil 并继续搜索 car 为零的实际 cons。