ELisp: Boolean (true false nil)

By Xah Lee. Date: . Last updated: .

Boolean in Emacs Lisp

in emacs lisp,

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

Equality Test

nil and t (ELISP Manual)

Emacs Lisp Boolean