As Mars0i says below, this is due to concat; more specifically, since map, partition, and concat all return lazy sequences, with recursion you are constructing a large chain of nested lazy sequences, as explained here:
http://stackoverflow.com/questions/5294055/why-am-i-getting-a-stackoverflow More in-depth analysis of a similar problem: https://www.ksmpartners.com/2014/01/clojure-lazy-seq-and-the-stackoverflowexception/ I applaud you for testing your solution with large n to make sure it's robust; since the 4clojure test cases all have n <= 11, my solution, and the solutions of those I follow, including many very good clojure programmers, also failed at large n. Keep up your good habits. On Monday, February 3, 2014 4:19:36 PM UTC-5, Andy Smith wrote: > > Hi, > > I am working through the 4clojure questions, I have a few different > solutions to problem 87 but all of them run out of stack space. I tried to > convert to using recur but I still have the problem. Why does this fail for > large n? > > ((fn pascal ([n] (pascal n [1])) ([n row] (if (= n 1) row (recur (dec n) > (map (partial reduce +) (partition 2 1 (concat [0] row [0]))))))) 500) > > Andy > -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.