On Fri, Jan 21, 2011 at 6:43 PM, Aaron Cohen <aa...@assonance.org> wrote: >> max-key uses destructuring, which was one of the culprits for >> unexpectedly holding onto the head of lists before locals clearing was >> added. > > This part of what I said is garbage, I'm sorry. I looked at max-key > too quickly, but there isn't any destructuring there.
I wrote my own implementation of max-key that doesn't use destructuring before reading the later part of this thread. :) It is here: (defn my-max-key [f & xs] (reduce (fn [v1 v2] (let [k1 (f v1) k2 (f v2)] (if (> k1 k2) v1 v2))) xs)) If the original code had blown the heap on my machine I was going to substitute my-max-key and see if it still did, and if it did tweak my-max-key to see if there was a way to make the problem go away. This my-max-key is less than perfectly efficient in that it keeps recomputing f of the current max-key; it's a no-frills version intended to be sure not to hold onto the head of anything, and to be simple and easy to tweak and debug. I'd have added saving f of current max-key later and seen if it still avoided blowing the heap on the original problem, and, if so, submitted it as a possible replacement for the core implementation of max-key. But that's moot now. It looks like one of the improvements to locals clearing in 1.2 fixed the OP's problem. -- 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