据我所知,NIL 是许多事物的符号:空列表或 bool 值 false。到目前为止一切顺利,但为什么有时输出中会出现 NULL?
clisp> (type-of NIL)
NULL
clisp> (type-of t)
BOOLEAN
clisp> (type-of (not t))
NULL
clisp> NIL
NIL
clisp> (eq NULL NIL)
ERROR..
所以 NULL 不是定义的符号,因为 "BASIC-STRING-6"
也不是。但是我对 NULL 这个术语有点困惑,因为 bool 值不管是否被取反都应该保持 bool 值。
最佳答案
NIL
是一个符号。它也被写成()
。 type-of
的输出在这里不一定有用。 HyperSpec 说 type-of :
Returns a type specifier, typespec, for a type that has the object as an element.
但是给定类型层次结构以及通用类型(所有类型都是 t
),type-of 的输出可能没有帮助。如果您想知道某物是否具有特定类型,这里更有用的是 typep .使用 typep,我们可以看到,无论 type-of 告诉我们什么,nil
是一个 bool 值、一个符号、一个列表和一个 null。另一方面,t 是一个符号,一个 bool 值,不是列表,也不是 null。
CL-USER> (type-of nil)
NULL
CL-USER> (type-of t)
BOOLEAN
CL-USER> (typep nil 'boolean) ; both are booleans
T
CL-USER> (typep t 'boolean)
T
CL-USER> (typep nil 'symbol) ; both are symbols
T
CL-USER> (typep t 'symbol)
T
CL-USER> (typep nil 'list) ; only nil is a list
T
CL-USER> (typep t 'list)
NIL
CL-USER> (typep nil 'null) ; only nil is a null
T
CL-USER> (typep t 'null)
NIL
关于lisp - Common Lisp 中 NULL 和 NIL 之间的确切区别是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23826145/