You're viewing version 1.2.0 of when. The latest stable version of Clojure Core is 1.3.0.
1.2.0 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:419 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: cons defmacro list test
Used in 170 other vars (expand)
empty dorun some cond await1 dotimes derive extend re-matches print-doc prn bases assert map when-first ref re-find intern to-array-2d filter re-seq ns when-let load interleave while bean range await take-while partition defmulti clojure-version gen-class disj merge-with take not-empty agent merge await-for browse-url *open-url-script* output-stream copy writer reader input-stream repl deftest- deftest test-all-vars inc-report-counter set-test emit-element down up right left encode print-stack-trace get-values get-value is-query-var? is-var? trace-datalog literal-magic? throw-if show expression-info start-handling-break find-javadoc-url lazy-walk status headers message browse-url *open-url-script* open-url-in-browser open-url-in-swing emit lcm pprint-map pprint-simple-list pprint-condp pprint-simple-code-list pprint-cond pprint-binding-form pprint-vector pprint-reader-macro exponential print-sql-exception-chain re-partition docodepoints partition docodepoints partition deftest- deftest test-all-vars inc-report-counter set-test tracer match children right-locs children-auto ancestors left-locs attr update-servlet-response run-jetty time-series-plot box-plot add-box-plot stacked-bar-chart bar-chart heat-map xy-plot histogram* pie-chart scatter-plot line-chart heat-map* function-plot add-points add-function add-lines stacked-area-chart area-chart add-histogram define-ant-type empty-directory eval-in-project deps -main make-pom new make-git-scm parse-github-url expand-subcontext-forms fail should-body when ns-wipe agent-watch-fn run-watcher needs-test? kill-nth-thread char-position compile-file-for-emacs position listener-eval find-or-spawn-repl-thread largest-common-prefix sldb-debug resolve-class potiential-classes-on-path variable-desc-for-echo-area compound-prefix-match? fuzzy-completions inspect-meta-information read-chars relative-path-name log-event ssh-shell ssh-exec sftp create-ssh-agent cartesian-product

Comments top

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