Elisp: Block of Expression (progn)
progn
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 several expressions into one single expression.
Most of the time it's used inside if.
(if 3 (progn "some more code here" "is true") (progn "some more code here" "is false")) ;; "is true"
progn returns the last expression in its body.
(progn 3 4 ) ; 4
prog1, prog2
prog1 and prog2 are similar to progn.
prog1return the first expression.prog2return the second expression.
(prog1 1 2 3) ;; 1 (prog2 1 2 3) ;; 2