Emacs Lisp: Boolean (true false t nil)
in emacs lisp,
- True is represented by the Symbol
't
or the variable t. Value of the variable t is symbol't
- False is represented by the Symbol
'nil
or the variable nil. Value of the variable nil is symbol'nil
nil is false, anything else is true.
Also, nil is equivalent to the empty list ()
, so ()
is also false.
There is no “boolean datatype” in elisp. Just remember that nil and empty list ()
are false, anything else is true.
And
by convention, the t
is used for true.
;; all false (if nil "yes" "no") (if () "yes" "no") (if '() "yes" "no") (if (list) "yes" "no")
By convention, the symbol t is used for true.
;; all true (if t "yes" "no") (if 0 "yes" "no") (if "" "yes" "no") (if [] "yes" "no") ; vector of 0 elements
Boolean Functions
and
(and t nil) ; nil ;; can take multiple args (and t nil t t t t) ; nil
or
(or t nil) ; t
not
(not t) ; nil (not nil) ; t (not 2) ; nil