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 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/d/optout.