Takes a body of expressions and yields a Delay object that will
invoke the body only the first time it is forced (with force or deref/@), and
will cache the result and return it on all subsequent force
calls. See also - realized?
;; In this example you can see that the first time the delay is forced ;; the println is executed however the second dereference shows just the ;; precomputed value. user=> (def my-delay (delay (println "did some work") 100)) #'user/my-delay user=> @my-delay did some work 100 user=> @my-delay 100
(defmacro delay
"Takes a body of expressions and yields a Delay object that will
invoke the body only the first time it is forced (with force or deref/@), and
will cache the result and return it on all subsequent force
calls. See also - realized?"
{:added "1.0"}
[& body]
(list 'new 'clojure.lang.Delay (list* `^{:once true} fn* [] body)))
Comments top
No comments for delay. Log in to add a comment.