Skip to content

promise

Turtle Kitty edited this page Jan 28, 2016 · 1 revision

promise

This macro allows lazy evaluation of expressions. It returns a promise, which must later be forced by calling the value method. This can be called multiple times; the expression executes but once.

(def count 0)
(def p
    (promise
        (seq
            (set! count count.inc)
            (* 3 4))))

p.value
    -> 12
count
    -> 1
p.value
    -> 12
p.value
    -> 12
count
    -> 1
Clone this wiki locally