Elisp: Boolean (true false nil)
Boolean in Emacs Lisp
There is no Boolean Type in elisp.
nil, 'nil,
and empty list (list ) are false, anything else is true.
nilis a builtin variable. Value ofnilis Symbol'nil.tis a builtin variable. Value oftis Symbol't. It is used to represent true by convention.
;; 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
Function Name Ending in p
Function names that end with letter “p” often means it returns boolean (i.e. nil or not nil).
(The “p” stands for “predicate”).
examples:
boundpbuffer-modified-pconspfboundpfeaturepfile-directory-pfile-exists-pfile-readable-pfunctionpintegerplistpnumberpstringpsymbolpvectorpzerop