user4813927
user4813927

Reputation:

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?

Upvotes: 5

Views: 1268

Answers (2)

Barmar
Barmar

Reputation: 781300

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.

Upvotes: 8

Terje D.
Terje D.

Reputation: 6315

Sort of. (and form t) will return t if form is not one of the false values nil or ().

I.e. it is a macro, not a function, and it requires the additional argument t to do the trick.

Upvotes: 3

Related Questions