Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Memoization in Clojure (arentz.ca)
37 points by st3fan on Nov 3, 2009 | hide | past | favorite | 6 comments


Of course the next step is to write an implementation of memoize that stores the entries in its maps using SoftReferences (http://java.sun.com/javase/6/docs/api/java/lang/ref/SoftRefe...). This way, anything stored in the cache will always be garbage collected before the JVM throws an OutOfMemoryError. I'm surprised that SoftReferences are not part of the default implementation given Clojure's nice Java interop as they would be perfect for a function like memoize.


Sent a patch to Rich, so we'll hopefully see it in the official implementation.


Awesome, you don't happen to have published the patch to github or Assembla have you? I have a suspicion that Rich will not replace the existing memoize with a SoftReference version as it is quite specific of the underlying architecture to provide this functionality. Rich is currently focused very much on CINC (Clojure in Clojure) and probably wants to avoid exposing implementation details to increase portability to other platforms (such as .NET). All the same, it would be great to have a SoftReference memoize in the contrib library for example.


Forgot about that. Looks like soft references are tied to the JVM as well (IKVM emulates them by waiting until a full run to collect).

http://github.com/fanatico/clojure/commit/aa78d57476806df10f...


I think my next step is actually to do something similar but then with memcache as the backing store instead of a local map.


I like the SoftReference idea btw!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: