Re: loop/recur being functional

2014-06-03 Thread James Reeves
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

Re: loop/recur being functional

2014-06-03 Thread Gary Trakhman
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

Re: loop/recur being functional

2014-06-03 Thread Matching Socks
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 members