common-lisp - 在字符串比较函数中使用 NIL 作为参数是否有效?

标签 common-lisp

我想知道 (string= "abc"nil) 在 Common Lisp 中是否有效。我注意到即使 nil 不是字符串,SBCL 也不会提示。 (string= '() nil) 返回 T 尽管两个参数都不是字符串...

(SBCL版本:2.2.2)

最佳答案

在 Common Lisp 中,字符串比较运算符接受“字符串指示符”。根据Reference Manual ,我们有:

string designator n. a designator for a string; that is, an object that denotes a string and that is one of: a character (denoting a singleton string that has the character as its only element), a symbol (denoting the string that is its name), or a string (denoting itself).

因此运算符接受符号,并比较它们的名称。

另一方面,空列表相当于符号NIL:

nil n. the object that is at once the symbol named "NIL" in the COMMON-LISP package, the empty list, the boolean (or generalized boolean) representing false, and the name of the empty type.

因此,比较相当于测试字符串 "NIL""NIL" 是否相等,这显然是正确的。

关于common-lisp - 在字符串比较函数中使用 NIL 作为参数是否有效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72069786/

相关文章:

common-lisp - 测试一个符号是否是 Common Lisp 中的 defstruct 名称

lisp - deftype - 变量未绑定(bind)

lisp - 符号表达式流 I/O

stream - 在 Common Lisp 中读取外部程序的二进制输出

common-lisp - 在Common Lisp中抓取HTML表?

heap-memory - 使用 SBCL 编译 lapack 系统时堆耗尽

Lisp - 从对列表中删除实例

function - 使用相同变量定义函数的最优雅/有效的方法

common-lisp - defgeneric 中的可选参数?

parameters - 普通口齿不清 : Working with &rest parameters