Emacs Lisp: If then else (Conditional)
The form for “if” expression is:
(if test body)
or
(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
when
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)