Next: 访问列表元素, Previous: 列表与 Cons 单元, Up: 列表 [Contents][Index]
下面这些判断函数用于检测一个 Lisp 对象是否为 atom原子、是否为 cons 单元、是否为列表,或是否为特殊对象 nil。(其中许多判断函数可以用其他函数定义,但因为使用非常频繁,所以单独提供它们是值得的。)
如果 object 是一个 cons 单元,该函数返回 t,否则返回 nil。nil 不是 cons 单元,尽管它 是 一个列表。
如果 object 是一个原子,该函数返回 t,否则返回 nil。除 cons 单元以外的所有对象都是原子。符号 nil 既是原子,也是列表;它是 Lisp 中唯一同时具备这两种属性的对象。
(atom object) ≡ (not (consp object))
如果 object 是 cons 单元或 nil,该函数返回 t;否则返回 nil。
(listp '(1))
⇒ t
(listp '())
⇒ t
该函数与 listp 相反:如果 object 不是列表,则返回 t,否则返回 nil。
(listp object) ≡ (not (nlistp object))
如果 object 是 nil,该函数返回 t,否则返回 nil。该函数与 not 完全等价,但为了代码清晰:当 object 被视为布尔真值时使用 not(参见 条件组合结构 中的 not),其他情况则使用 null。
(null '(1))
⇒ nil
(null '())
⇒ t
如果 object 是 proper list正规列表,该函数返回其长度;否则返回 nil(see 列表与 Cons 单元)。正规列表除了满足 listp 外,还必须既不是循环列表,也不是点列表。
(proper-list-p '(a b c))
⇒ 3
(proper-list-p '(a b . c))
⇒ nil
Next: 访问列表元素, Previous: 列表与 Cons 单元, Up: 列表 [Contents][Index]