Excellent -- thanks all. The binding approach works very well.
On Mar 19, 11:40 am, Jason Wolfe wrote:
> For recursive one-shot memoized functions, I've been using this:
>
> (defmacro memoized-fn [name args & body]
> `(let [a# (atom {})]
> (fn ~name ~args
> (let [m# @a#
>
For recursive one-shot memoized functions, I've been using this:
(defmacro memoized-fn [name args & body]
`(let [a# (atom {})]
(fn ~name ~args
(let [m# @a#
args# ~args]
(if-let [[_# v#] (find m# args#)]
v#
(let [v# (do ~...@body)]
No, it won't force a GC. But it should be eligible for GC, if that's
what you mean. Hopefully the memo cache will stay in the
generation-zero nursery, in which case it will incur effectively no GC
cost since the nursery collector runs in time O(live objects in
nursey) rather than O(total objects in
Ah, is there any concern with pummeling that var?
On Mar 19, 2:22 am, Meikel Brandmeyer wrote:
> Hi,
>
> On Mar 19, 7:05 am, Greg Fodor wrote:
>
> > Ah, I think I have the solution:
>
> > (defn foo []
> > (let [bar-memoized (memoize bar)]
> > ; Do stuff with bar-memoized
> > ))
>
> > Seem
Hi,
On Mar 19, 7:05 am, Greg Fodor wrote:
> Ah, I think I have the solution:
>
> (defn foo []
> (let [bar-memoized (memoize bar)]
> ; Do stuff with bar-memoized
> ))
>
> Seems to work -- to verify, this will GC the memoized cache for bar
> after each call to foo, right?
Yes. I would thin
On Fri, Mar 19, 2010 at 06:56, Greg Fodor wrote:
> I would like to memoize bar such that the memory used for memoization
> is GC'ed at the end of the call to foo, and additionally the cache
> used for memoization is thread local (so no need for heavyweight
> synchronization tools like atoms, etc
Ah, I think I have the solution:
(defn foo []
(let [bar-memoized (memoize bar)]
; Do stuff with bar-memoized
))
Seems to work -- to verify, this will GC the memoized cache for bar
after each call to foo, right?
On Mar 19, 1:56 am, Greg Fodor wrote:
> Hi there -- I am looking for a soluti