lisp - Common Lisp 中 NULL 和 NIL 之间的确切区别是什么?

标签 lisp common-lisp null

据我所知,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/

相关文章:

apache - 可以使用 Apache Tomcat 的 Lisp 方言吗?

lambda - 了解非法嵌套 `lambda` 调用

common-lisp 高阶逻辑或函数

ios - TableView :cellForRowAtIndexPath called with nil indexPath after deleting item

lisp - 执行存储为列表的代码

binding - 在不传递变量名的情况下在函数内重新分配全局变量

mysql - 在数据库中找不到空值

ios - Swift Admob 插页式错误

xml - Common Lisp Closure XML 包中广播处理程序的无效输出

common-lisp - Common Lisp 中格式指令的安全解析