Emacs Lisp: Boolean (true/false) (t/nil)

By Xah Lee. Date: . Last updated: .

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 t nil) ;  nil

;; can take multiple args
(and t nil t t t t) ;  nil


(or t nil) ;  t


(not t) ;  nil
(not nil) ; t

(not 2) ;  nil

Comparing Number Order (Greater/Lesser)

;; less than
(< 3 4)
;; t

;; greater than
(> 3 4)
;; nil
;; less or equal
(<= 3 4)
;; t

;; greater or equal
(>= 3 4)
;; nil

Equality Test

(info "(elisp) nil and t")

Lisp Basics

ErgoEmacs mascot-s276x226
Buy Xah Emacs Tutorial

Lisp Basics


Lisp Data Structure


Lisp Symbol

Lisp Misc

Working with Elisp