您的位置:首页 > 编程语言

Common Lisp – assoc 函数的示例代码

2013-05-06 13:59 417 查看
;;ASSOC function searches supplied list for cons cell that have item as car part. Return value is the cell with key-value pair which key matched testing conditions, otherwise NIL. Default comparison operator is EQL.

;;Associative list, or for short alist, is a list with key-value pairs in cons cells. That is ((key1 . value1) (key2 . value2) ...)

(assoc 'a '((a . 1) (b . 2) (c . 3))) => (A . 1)
(assoc 'x '((a . 1) (b . 2) (c . 3))) => NIL
(assoc 'b '((a . 1) (b . 2) (c . 3) (b . 4))) => (B . 2)
(assoc "b" '(("a" . 1) ("b" . 2))) => NIL
(assoc "b" '(("a" . 1) ("b" . 2)) :test #'equal) => ("b" . 2)
(assoc 7 '((6 . a) (9 . b)) :key #'1+) => (6 . A)
(assoc 5 nil) => NIL


Reference: http://jtra.cz/stuff/lisp/sclr/assoc.html
S.K.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: