Thanks for the explanation, Meikel. My statement about anti-pattern was predicated on each call to fn[] creating a new class - I see from your explanation and from going back and re-reading Rich's old posts on this topic that I misunderstood it before. (If it did create a new class each time, I'd hold my stance on it being an anti-pattern...)
However, in practical use I've found that in a deeply nested application similar to the OP's genetic programming system that removing inline function definitions in favor of explicitly defining them as top-level named functions provides a significant boost in speed and reducation in PermGen usage. I must be missing something simple, but I can't figure out why PermGen would be affected if no classes are created. I think this line of discussion might actually merge with another thread I started yesterday: http://groups.google.com/group/clojure/browse_thread/thread/67f9d2df248d3aa0 (thought they were related but I didn't want to hijack this thread...) -Greg On Jan 25, 3:38 am, Meikel Brandmeyer <m...@kotka.de> wrote: > > Every function in Clojure creates a class. So if one encounters a > (fn [a b] (+ a b)) at runtime, there is simply a new class instance > created, which is then .invoked with values for a and b. So the > number of "functions" is known at compile time. Note: macros > happen at compile-time, so functions generated by a macro are > also known at compile-time. At runtime there is simply an instance > which gets gc'd. > > So saying "anonymous functions in general might be a sort of > anti-pattern" is equal to saying "Vectors in general might be sort > of anti-pattern", because there is nothing different happening. > > I didn't follow the thread in much detail, but that is what I have > left in my memory: > > What might be an anti-pattern is using eval. Ok ok. I know eval > has its uses, but using eval with fn might be an anti-pattern. > From my point of view, the following is happening: > One calls (eval '(fn ....)). Each and every call to eval creates > a new class. Even for identical fn's. So what cloggs the memory > are not the function instances themselves. They get gc'd. But > the generated classes stay in memory. They don't go away. > This is what brings down the system finally. > > (eval '(fn ..)) should not be a thing you should find in a "long > running server application". Maybe only in form of debug repl. > But generating enough fn classes in that repl to bring down the > server.... > > Does this make sense? > > Sincerely > Meikel > > smime.p7s > 5KViewDownload --~--~---------~--~----~------------~-------~--~----~ 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 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 -~----------~----~----~----~------~----~------~--~---