To be even more pedantic, clojure does not guarantee that tail calls will be optimized. This is due to the lack of support in many of the jvm implementations. There is a post on using avian, a jvm implementation that supports TCO, that allows clojure to support TCO with little modification. http://groups.google.com/group/clojure/browse_thread/thread/5388b89d5b187e2f/e19a578f1a0ea6d3?lnk=gst&q=tail+call#e19a578f1a0ea6d3
On Aug 2, 4:47 pm, David Nolen <dnolen.li...@gmail.com> wrote: > On Tue, Aug 2, 2011 at 4:43 PM, Trastabuga <lisper...@gmail.com> wrote: > > I just came across the issue of getting the StackOverflowError in the > > function reading long file and recursively building a list of data. > > After I replaced function name with "recur" the problem went away. > > Hence a couple of questions. It's the programmer's responsibility to > > put recur instead of function names where tail-recursion is available? > > (Kind of obvious, but then why the compiler wouldn't detect it?) > > If tail-recursion is not available and function name has to be called, > > how do I deal with stack overflow in this case? > > Clojure does not have tail call optimization. You must use recur, > trampoline, or redesign your code around lazy sequences. > > David -- 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