null
null System Class
Class Precedence List:
null, symbol, list, sequence, t
Description:
The only object of type null is nil, which represents the empty list and can also be notated ().
See Also:
Section 2.3.4 (Symbols as Tokens), Section 2.4.1 (Left-Parenthesis), Section 22.1.3.3 (Printing Symbols)
Expanded Reference: null (System Class)
The null type
The type null has exactly one object: NIL. NIL is simultaneously the empty list, the boolean false, and a symbol.
(typep nil 'null)
=> T
(typep '() 'null)
=> T
(typep t 'null)
=> NIL
Class precedence list
The class precedence list for null is: null, symbol, list, sequence, t. NIL is both a symbol and a list.
(typep nil 'symbol)
=> T
(typep nil 'list)
=> T
(typep nil 'sequence)
=> T
NIL as empty list and false value
NIL plays dual roles in Common Lisp: it is the empty list and the canonical false value.
;; As the empty list
(length nil)
=> 0
(append nil '(a b))
=> (A B)
;; As false
(if nil "true" "false")
=> "false"
(not nil)
=> T
Null is the only type with a single member
;; Only NIL is of type null
(remove-if-not (lambda (x) (typep x 'null))
'(0 nil "" () t))
=> (NIL NIL)
Relationship to cons and list
The types cons and null form an exhaustive partition of the type list. Every list is either a cons or null.
(subtypep 'null 'list)
=> T
=> T
(subtypep 'null 'cons)
=> NIL
=> T