Nice, but it won't work for me, since I'm trying to avoid computing all the values in the table, and so I can't use the pump-priming approach. I don't know what values I'm going to need primed! I'm sure there are ways round it, but I think they're all complicated and ugly.
I think I'll translate my program into python, where presumably it will just work. Or actually you've reminded me about Racket. I used to like that when it was PLT scheme. This recursion limit really is quite nasty. I could probably live with 4000, but 200? And why would memoization make it worse anyway? Is it possible to increase the stack size somehow? Or would that use up all the memory? Cheers, John. On Sunday, September 22, 2013 6:40:11 PM UTC+1, puzzler wrote: > > Check out my blog article from last year and search for the spot where I > describe the "priming the pump" trick: > > http://programming-puzzler.blogspot.com/2012/11/coin-change-kata-in-racket-and-clojure.html > > If the simplest way to write the solution to your problem is to use a > top-down form of memoization, you can still avoid blowing the stack by > running it in a bottom-up fashion a la traditional dynamic programming. > > > On Sun, Sep 22, 2013 at 8:19 AM, John Lawrence Aspden < > asp...@googlemail.com <javascript:>> wrote: > >> Hi Guys, >> >> I'm trying to memoize a fairly complicated double recursion, and it's >> blowing stack after not terribly many calls. >> >> I've reduced the problem to a simple test case, summing from 1 to n : >> >> user=> (clojure-version) >> "1.5.1" >> user=> (def gauss-recurse (fn [n] (if (< n 1) 0 (+ n (gauss-recurse (dec >> n)))))) >> #'user/gauss-recurse >> user=> (gauss-recurse 3500) >> 6126750 >> user=> (def gauss-memoized (memoize (fn [n] (if (< n 1) 0 (+ n >> (gauss-memoized (dec n))))))) >> #'user/gauss-memoized >> user=> (gauss-memoized 160) >> >> StackOverflowError clojure.lang.RT.boundedLength (RT.java:1654) >> user=> >> >> >> Does anyone know why this would happen? Do I just have to give up on >> memoization and find another way to do dynamic programming? >> >> Cheers, John. >> >> -- >> -- >> You received this message because you are subscribed to the Google >> Groups "Clojure" group. >> To post to this group, send email to clo...@googlegroups.com<javascript:> >> Note that posts from new members are moderated - please be patient with >> your first post. >> To unsubscribe from this group, send email to >> clojure+u...@googlegroups.com <javascript:> >> 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+u...@googlegroups.com <javascript:>. >> For more options, visit https://groups.google.com/groups/opt_out. >> > > -- -- 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.