我想知道 (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/