gpt4 book ai didi

lisp - assoc 只是 find 的语法糖吗?

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

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)

在我看来 assoc 只是 find 的一个特例,这是真的还是我缺少 assoc 的一些额外功能> 这在这里不是很明显吗?

最佳答案

来自 clhs.lisp.se/Body/f_assocc.htm :

The two expressions

(assoc item list :test fn)

and

(find item list :test fn :key #'car)

are equivalent in meaning with one exception: if nil appears in alist in place of a pair, and item is nil, find will compute the car of the nil in alist, find that it is equal to item, and return nil, whereas assoc will ignore the nil in alist and continue to search for an actual cons whose car is nil.

关于lisp - assoc 只是 find 的语法糖吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20139672/

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