Corece到Common Lisp中的布尔值

时间:2018-10-29 15:09:18

标签: boolean common-lisp coercion

Common Lisp中是否有内置函数可以将任何内容强制转换为布尔值,就像Python中的bool函数一样?

2 个答案:

答案 0 :(得分:6)

没有专门为此目的。您不能使用boolean作为coerce的类型参数。您可以使用:

(defun boolean-value (x)
  (not (not x)))

这类似于许多其他语言中使用的!!x习惯用法。

答案 1 :(得分:2)

排序。如果(and form t)不是错误值tform之一,nil将返回()

,它是一个宏,而不是一个函数,并且需要附加参数t才能实现。