Elisp: Boolean (true false nil)

By Xah Lee. Date: . Last updated: .

Boolean in Emacs Lisp

There is no Boolean Type in elisp.

nil, 'nil, and empty list (list ) are false, anything else is true.

;; all false
(if nil "true" "false")
(if 'nil "true" "false")
(if () "true" "false")
(if '() "true" "false")
(if (list) "true" "false")

By convention, t is used for true.

;; all true
(if t "true" "false")
(if 0 "true" "false")
(if "" "true" "false")
(if (vector ) "true" "false")

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

Reference

Elisp, Boolean