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?
Corece to boolean in Common Lisp
Asked Answered
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.
Me, too, I just didn't want to open up the "what's the difference between
NOT
and NULL
" can of worms. –
Cheree ... so what is the difference? –
Luedtke
@Luedtke There's no operational difference. The difference to programmers is that
NOT
is for logical testing, while NULL
is for structural testing. –
Cheree 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.
© 2022 - 2024 — McMap. All rights reserved.
(not (null x))
more often as idiom, but both work. – Christly