the lazy sequence created repeatedly
is returned from the form and then implemented only when printing via REPL after the binding has been "unwound", and just at that moment an anonymous function is called. To make sure this is the case, try these two options:
(binding [*d* 2]
(println *d*)
(let [x (repeatedly 1 #(println *d*))]
(println (realized? x))
x))
and
(binding [*d* 2]
(println *d*)
(doall (repeatedly 1 #(println *d*))))
The second variation causes the sequence to be fully implemented while still within the bounding area.
, "" bound-fn
:
(binding [*d* 2]
(println *d*)
(repeatedly 1 (bound-fn [] (println *d*))))