Recommended: "Programming Clojure", in which Stuart Halloway & Aaron Bedra
discuss these forms of recursion.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new membe
Have you considered the similarity between loop-recur and sequence
operations?
IE, tail-recursion turns the call stack into a sequence of states. The
nice trick you can play in clojure is to reify this sequence as a lazy
sequence.
(take 5 ((fn this-fn [last] (cons (inc last) (lazy-seq (this-fn (
loop/recur is explicit tail recursion, and therefore will only work if the
"recur" is in the tail position, i.e. the last form evaluated.
For example, this function is tail recursive:
(defn sum [coll result]
(if (seq coll)
(sum (rest coll) (+ result (first coll)))
0))
While this functi
I'm trying to “internalize” loop/recur as being a functional construct.
I'm sure I'm not alone in this: I initially struggled with it, with my view
unduely influenced by its implementation, especially when multiple loop
heads are present. (It could be viewed as vulgar but necessary imperative
o