Search code examples
booleancommon-lispcoercion

Corece to boolean in Common Lisp


Is there a build-in function in Common Lisp to coerce any thing into it's boolean value, like the bool function in Python does?


Solution

  • There's nothing specifically for this. You can't use boolean as the type argument to coerce. You can use:

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

    This is analogous to the !!x idiom used in many other languages.