In the example code below I return a lazy list. What I would like to happen when someone calls count on the list is that some arbitrary function get executed instead and returns whatever I like.
(defn my-range [i limit]
(lazy-seq
(when (< i limit)
(cons i (my-range (inc i) limit)))))
(count (my-range 0 9)) returns whatever
I'm not sure if this should be possible: I have been looking at reify
but can't figure out if it can be used in this situation.