Emacs Lisp: Block of Expression
Sometimes you need to group several expressions together as one single expression. This can be done with progn
.
(progn (message "a") (message "b")) ;; is equivalent to (message "a") (message "b")
The purpose of (progn …)
is similar to a block of code {…}
in C-like languages.
It is used to group together a bunch of expressions into one single parenthesized expression.
Most of the time it's used inside “if”.
(if something (progn ; true ;; code here ) (progn ; else ;; code here ))
progn
returns the last expression in its body.
(progn 3 4 ) ; 4