Why isn't there a BOOLEANP predicate?
Asked Answered
A

2

6

To check for a symbol, one might use symbolp. To check for a number, one might use numberp. And so on…

Why is there no booleanp to check for a boolean value? Of course I can use

(defun booleanp (x)
  (or (null x)
      (equal x t)))

but is there an easier (built-in) way of doing this? If not, is there a special reason, why just this predicate is missing?

Addiel answered 8/4, 2015 at 16:35 Comment(4)
Is boolean an actual type, or just a convention for how to interpret other types?Gerber
I'm not sure if I got your question correctly (probably not), but since (type-of t) returns boolean I thought that it is an actual type. Isn't it? OTOH nil is (of course) not of type boolean, since it's equivalent to the empty list. Hmmm…Addiel
boolean is a type. see l1sp.org/cl/booleanConnate
NIL is of type boolean. It is also of type LIST. An object may be of many types. Consider 1: it's of type bit, integer, and unsigned-byte.Connate
C
14

I don't know the exact history of numberp, symbolp, the boolean type, and other type predicates, but with the availability of the generic type predicate typep it is not necessary to have a separate predicate for every type. A short way to see if something is of type boolean is (typep object 'boolean).

Connate answered 8/4, 2015 at 16:43 Comment(0)
O
2

I'd dare to guess that the real reason for this is that even though only NIL and T are (TYPEP 'BOOLEAN), any value is a valid boolean expression. I.e. any value except for NIL is considered true in an IF form. Thus, the usefulness of a BOOLEANP would be limited, if not harmful as it would return false for things that are perfectly valid input to the conditional forms.

Oxyacid answered 10/4, 2015 at 8:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.