Clojure: Expression Group

By Xah Lee. Date: . Last updated: .

Sometimes you need to group several expressions together as one single expression. This can be done with do. (do is like lisp's progn)

    (pr "a")
    (pr "b"))

;; is equivalent to

    (pr "a")
    (pr "b")

Most of the time it's used inside if .

For example:

(if something
  ; true body
  ; else body

do returns the last expression in its body.

(do 3 4 ) ;  4