Package enhanced-boolean
Description
Simply (:shadowing-import-from #:enhanced-boolean #:
from your defpackage. Don't boolean
)(:use)
!
enhanced-boolean
provides a canonical way of converting generalized booleans to booleans.
Traditionally, if you wanted to convert a generalized boolean to a boolean, there were multiple equivalent ways to do it, none of which is clearly the canonical way or particularly compelling:
(not (null foo))
(if foo t nil)
(when foo t)
It's particularly painful if you need a function that does this:
(mapcar (lambda (value)
(not (null value)))
'(t true nil false 0 () #() "" #\0))
(defun %boolean (value)
(not (null value)))
(mapcar #'%boolean '(t true nil false 0 () #() "" #\0))
The crux of the problem is that the Common Lisp standard unfortunately omits to specify this trivial function (which users are forbidden from defining directly on the standard symbol boolean):
(defun boolean (generalized-boolean)
(if generalized-boolean
t
nil))
This unfortunate omission has personally caused me extensive and repeated inconvenience and agony over the years (as this greatly offends my sense of aesthetics), as well as to many others I'm sure. In many programming languages, such an unfortunate limitation to a built-in construct could not be easily or satisfactorily overcome, and might even require help from the language's designers and implementors to vanquish, if ever even accomplished, even after years of begging. (For instance, many languages have a predefined list of reserved keywords with hardcoded behavior.)
enhanced-boolean simply provides a portable, robust, performant version of this function that acts as a drop-in replacement for cl:boolean.
Simply (:shadowing-import-from #:enhanced-boolean #:
from your defpackage. Don't boolean
)(:use)
!
generalized-boolean => boolean
Returns nil
if generalized-boolean is nil
, else returns t
.
To help ensure proper optimization, this function is declaimed inline, its ftype is declared, and an appropriate compiler macro is defined so that sophisticated code walkers can fully optimize the code as if it had been written out by hand.
Expands to type cl:boolean.