Emacs Lisp: If then else (Conditional)

By Xah Lee. Date: . Last updated: .

The form for “if” expression is:

(if test body)


(if test true_body false_body)

(if (< 3 2)
    (progn 8)
  (progn 7))
;; 7

;; if no false clause, return nil
(if (< 3 2)
    (progn 8))
;; nil


If you do not need a “else” part, you can use the function when , because it is more clear. The form is:

(when test expr1 expr2 etc)

Its meaning is the same as

(if test (progn expr1 expr2 etc) nil)

Control Structures (ELISP Manual)