When a function is given a large lazy seq, it is beneficial to avoid retaining the head, so that in case the fully realized sequence does not fit in memory, you can still process it. For example, this works fine:
(count (take 10000000 (range)))
(reduce + (take 10000000 (range)))
But this can generate an out of memory error:
(defn recount [coll n]
[(count (take n coll))
(reduce + (take n coll))])
(recount (range) 10000000)
because the binding of coll retains the head of the sequence when count realizes the lazy seq.
The closest thing I can come up with is a macro that forces the seq to be reevaluated instead of bound:
(defmacro recount4 [coll n]
`[(count (take ~n ~coll))
(reduce + (take ~n ~coll))])
(recount4 (range) 10000000)
This does not seem to be broadly applicable.
I looked at this blog, but the solution is less than satisfying due to the use of atoms and mutable state.