On Dec 2, 8:13 pm, "john.holland" <jbholl...@gmail.com> wrote: > Thanks for all the replies. It seems to me that as general solutions to > stack overflow, trampoline and recur are > very valuable. I had gotten the mistaken idea that Scheme was somehow > immune to the problem. > My experiments in Scheme seemed to get to higher amounts of recursion > before blowing up than my Clojure did, > but they are both susceptible to it. Are there things like trampoline and > recur in Scheme? In Lisp? Well yes, but they are not explicitly specified since Scheme automatically optimizes tail calls. Consider this example: (define (fact n) (if (< n 2) 1 (* n (fact (- n 1))))) This is not tail recursive and eventually blows the stack ... in Scheme and in Clojure. (define (fact-accu n res) (if (< n 2) res (fact-accu (- n 1) (* n res)))) Here, the recursive call is in tail position and gets optimized by the Scheme compiler. In Clojure you would have to call recur instead, otherwise your stack grows. In Scheme this is not necessary since the optimization is always done if possible. Thus, there is no special syntactic marker, i.e. reserved word, for this. (Same holds for mutual recursion <-> trampoline). In Common Lisp the situation is somewhat unfortunate, since tail call optimization is implementation dependent. So, you cannot rely on it and therefore loop/tagbody etc are your friends there.
Hope this helps, Nils > > John Holland -- 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