On Dec 1, 2:14 pm, Stuart Sierra <the.stuart.sie...@gmail.com> wrote: > Tree-building functions are not usually tail-recursive. I'm not even sure > that Scheme will do tail-call elimination in that case. The Java stack can > hold 8000 frames or so, so log base 2 is probably small enough to avoid a > stack overflow when building a tree. > > You could probably rewrite this with loop/recur, but I don't have time to > work it out just now.
You can generally rewrite any stack-heavy code to use loop/recur, by managing your own "stack of tasks" on the heap. It's usually not much of a win because you have to use the same amount of memory (or more), but by keeping it on the heap you can avoid stackoverflows for unusually deep recursions. I have an example at http://stackoverflow.com/questions/8045839/recursion-over-a-list-of-s-expressions-in-clojure/8045946#8045946 -- 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