The JVM does not currently support tail call optimization (TCO) so any tail recursion call is actually calling the function on itself using the stack to hold new bindings. TCO hides this to you when it's supported by the language and transforms this into a loop.
Recur will not consume the Java stack and eventually blow it if the recursion level is huge. You are reusing existing bindings by specifying new values (recur ...) for them. No new stack frames are needed. It's an explicit loop. You can increase the stack size when starting the JVM but you always have that dangling limit somewhere. Depending on what your code does you may blow it even if you increase it significantly. Luc P. On Wed, 26 Jan 2011 07:04:51 -0800 (PST) Harrison Maseko <lis...@gmail.com> wrote: > Hi all, > I need some help in understanding some basic concept. The book > Programming Clojure on pages 134 - 136 deals with tail recursion and > self-recursion using recur. The tail recursive example blows the stack > while the self-recursive function using recur presented on page 135 > does not. On page 136 the book says that "the critical difference > between tail-fibo (tail recursion) and recur-fibo (self-recursion > using recur) is on line 7, where recur replaces the call to fib." Why > does recur make such a difference in the way the function consumes > resources? What really is the difference between a tail-recursive > function and a recursive function using recur? > Thanks for your help. > -h. > -- Luc P. ================ The rabid Muppet -- 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 are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en