In Common Lisp, NIL is a symbol and a list and a Boolean.
$ sbcl
* (symbolp nil)
T
* (listp nil)
T
* (consp nil)
NIL
Is there a boolean predicate? My Common Lisp is rusty and I don't see one at https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node73.html#S....Can you suggest any example Common Lisp programs that print the _types_ NULL or NIL or T? Or show off the benefits of this spindle arrangement? I can intuitively see the benefits of this approach, but an example makes things much more memorable.
;; catch-all method for any type
(defmethod foo ((arg t)) ...)
;;
(defmethod foo (arg ...) ...) ;; alternative spelling: omit class
NIL is the empty list and that is mnemonic for "empty type". For instance, the intersection of two mutually exclusive types is the empty type. Nothing can be both a cons and an atom, so the type denoted by the type expression (and cons atom) is empty; and that is nil. The set manipulation which underlies types needs an empty set, and nil fill the need for that empty set (pun intended).NULL is useful in writing methods that capture NIL (the only instance of NULL). That may be recognized as the "null object pattern":
(defmethod foo ((arg null))
;; (foo nil) called
)
(defmethod foo ((arg number))
;; (foo <number>) called
)
(defmethod foo ((arg t))
;; (foo <anything else>) called
)Nope, because everything is a Boolean: NIL is false, and everything else is true.
(defun booleanp (x) (TYPEP x 'BOOLEAN))