Re: scoped local memoize

2010-03-19 Thread Greg Fodor
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# >          

Re: scoped local memoize

2010-03-19 Thread Jason Wolfe
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)]

Re: scoped local memoize

2010-03-18 Thread Per Vognsen
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

Re: scoped local memoize

2010-03-18 Thread Greg Fodor
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

Re: scoped local memoize

2010-03-18 Thread Meikel Brandmeyer
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

Re: scoped local memoize

2010-03-18 Thread B Smith-Mannschott
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

Re: scoped local memoize

2010-03-18 Thread Greg Fodor
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