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 <
aspd...@googlemail.com> 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 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.
>

-- 
-- 
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.

Reply via email to