(when test & body)
Evaluates test. If logical true, evaluates body in an implicit do.
user=> (when (= 1 1) true)
true
user=> (when (not= 1 1) true)
nil
user=> (def has-value (when true
(println "Hello World")
"Returned Value"))
Hello World
#'user/has-value
user=> has-value
"Returned Value"
;; See examples for "if" explaining Clojure's idea of logical true
;; and logical false.
;; When is a macro of (if .. do ..)
user=> (macroexpand '(when 1 2 3 4))
(if 1 (do 2 3 4))
;; if 1 is true, do will evaluate 2 3 4, but return values of 2 and 3 would be
;; ignored. Value of 4 (last value) would always be returned.
;; See https://clojuredocs.org/clojure.core/do for details
user=> (if 1 (do 2 3 4))
4