Adding metadata to an object produces a new object, rather than altering the existing object. Every time you increment the counter for a function in p it becomes different, and the memoize treats it as new. That is, p-apply-memoized takes parameters p and v. Your post-walk over p replacing functions with copies with changed metadata changes p:
user=> (def q (fn [x] (inc x))) #'user/q user=> (= q (with-meta q {:foo true})) false Since functions have object identity for =, and adding metadata changes object identity, the function is not = to its meta-added self -- and that means a collection containing the function also is not = to a copy produced using post-walk and meta-izing functions in the collection, and that means a data structure built of collections and containing functions and post-walked to meta-ize the functions is not = to its un-metaized self. So, each time p-apply-memoized gets called with "the same" p, because all the counters have been bumped, it's not actually the same p as far as memoize is concerned, and so you don't get the benefits of memoization anymore. Solution: don't mess with the function metadata. Instead, use a global map from fns to counts, or something. -- 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