Oops--I do get a stack overflow error if I give it 959 or greater as the argument, instead of 500. It looks like the error is not from the explicit recursion, but is due to concat. Someone who knows more than I do will have to explain this.
user=> ((fn pascal ([n] (pascal n [1M])) ([n row] (if (= n 1) row (recur (dec n) (map (partial reduce +) (partition 2 1 (concat [0] row [0]))))))) 959) StackOverflowError clojure.core/concat/fn--3923 (core.clj:678) (user=> (pst) StackOverflowError clojure.core/concat/fn--3923 (core.clj:678) clojure.lang.LazySeq.sval (LazySeq.java:42) clojure.lang.LazySeq.seq (LazySeq.java:60) clojure.lang.RT.seq (RT.java:484) clojure.core/seq (core.clj:133) clojure.core/concat/cat--3925/fn--3926 (core.clj:687) clojure.lang.LazySeq.sval (LazySeq.java:42) clojure.lang.LazySeq.seq (LazySeq.java:60) clojure.lang.RT.seq (RT.java:484) clojure.core/seq (core.clj:133) clojure.core/partition/fn--4309 (core.clj:2834) clojure.lang.LazySeq.sval (LazySeq.java:42) On Monday, February 3, 2014 3:19:36 PM UTC-6, 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.