Graph from prismatic/plumbing [ https://github.com/Prismatic/plumbing <https://github.com/Prismatic/plumbing> ] provides memoization/delayed-execution allowing you to maintain a map-like structure whilst deferring and caching calculations.
Rob. > On 26 Jan 2015, at 09:17, David James <[email protected]> wrote: > > I just renamed the subject line since my question has nothing inherently to > do with heuristic search. (That was just my particular use case.) This kind > of thing can happen in any codebase where destructuring of function arguments > is used. > > On Monday, January 26, 2015 at 12:16:04 PM UTC-5, David James wrote: > Background: I'm implementing a heuristic search over a tree of possibilities. > The heuristic calculation runs over a map of state. I have a large number of > nested functions that support this heuristic. So, for convenience, I often > pass around `state` as the first argument in these functions. Inside, I use > the :keys destructuring style. > > Commentary: This approach is convenient; however, I feel like I've veered > towards one of the pitfalls of OO programming, where this "convenient" > composition of data hides the essence of the problem. In contrast, in other > projects, I've done lots of memoization -- this is easy when all arguments > are explicit. > > Questions: Have others faced this tradeoff? How do you think about it? How do > you strike a balance, if there is one? More pointedly, is there a way to get > the best of both worlds (e.g. the "composed" argument style AND memoization)? > > Possible Solution: What about writing a macro to help? It would not be hard > to handle the memoization of some 'base-level' functions: > > (defn f1 [{:keys [a b] :as state}] :costly-calculation-of-a-b) > (defn f2 [{:keys [b c] :as state}] :costly-calculation-of-b-c) > > However, when it comes to a chain of functions, the memoization is not > apparent: > > (defn f3 [{:keys [x] :as state}] (+ (f1 state) (f2 state) (g x))) > > In order to memoize `f3`, one would need to account for not only `x` but also > `a`, `b`, and `c`. This would be an improvement over memoizing the entire > state. > > Any thoughts on this kind of solution? Has it already been done? Are there > other, possibly better, ways to address this overall challenge? > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to [email protected] > Note that posts from new members are moderated - please be patient with your > first post. > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > <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 [email protected] > <mailto:[email protected]>. > For more options, visit https://groups.google.com/d/optout > <https://groups.google.com/d/optout>. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] 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 [email protected]. For more options, visit https://groups.google.com/d/optout.
