Clojure: To Recurse or Not To Recurse

As I start week number 5 of my CodeLesson Clojure course and look at programming examples, it is clear to me that when to use recursion or not is a fuzzy science. Most Clojure text books talk about using sequences wherever possible and not even using loop/recur (Clojure’s tail recursion method)  let alone recursion without loop/recur. The Clojure Google Groups even called this method low-level while pushing using sequences.

One assignment in particular I found particularly tricky, because it involved how to make change for some number of dollar bills, and the official solution used recursion even without wrapping the sequence inside a lazy-seq function. So, I conclude individual preference and what makes sense will have to prevail concerning Clojure and recursion.

3 thoughts on “Clojure: To Recurse or Not To Recurse

  1. Actually I think that in the offical Solution you can use Recursion safely without Lazy-seq because from the Problem Domain it is sure that the Recursion Never gets to be indefintiv so you never get a Stack overflow…I find Recursion a very Natural Tool for these Kinds of Problems …

    1. I’m glad to hear your take on this, because while it is good to be flexible and think outside the box, if Clojure has tail recursion set up and it works, then why not use it.

  2. using lazy-seq is very similar to how you can use recursion in haskell, for me is almost the same sh%$..now..the loop recur I think is very ugly and it seem most to calling a “for” loop in an imperative language..it seems exist only for the jvm limitations but when you use f# it has a better implementation for recursion..really I don’t know which are the difference in the limitation between both plataforms…but I think than loop recursion is really a ugly spot in the clojure face…..

Leave a reply to John Cancel reply