1.3.0 permalink Arrow_down_16x16
  • (when test & body)
Evaluates test. If logical true, evaluates body in an implicit do.

3 Examples top

  • 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.
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:454 top

(defmacro when
  "Evaluates test. If logical true, evaluates body in an implicit do."
  {:added "1.0"}
  [test & body]
  (list 'if test (cons 'do body)))
Vars in clojure.core/when:
Used in 0 other vars

Comments top

No comments for when. Log in to add a comment.