Re: Binding values in a list of symbols and evaluating as code

2009-01-25 Thread Zak Wilson
I think using eval is generally considered an antipattern. It's generally slow, and it's easy to make confusing code with it. Phlex - thanks for the suggestion. I may give that a try. Rich - thanks for the fix. I'm trying it now. It looks like it's not experiencing any permanent growth, though i

Re: Binding values in a list of symbols and evaluating as code

2009-01-25 Thread Greg Harman
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

Re: Binding values in a list of symbols and evaluating as code

2009-01-25 Thread Rich Hickey
On Jan 25, 2009, at 5:13 AM, Christophe Grand wrote: > > Zak Wilson a écrit : >> Thanks, Christophe. It works now, and it's fast. >> >> Unfortunately, now I've run in to Nathan's problem. After a few >> thousand generations, resulting in the creation of about half a >> million functions it was u

Re: Binding values in a list of symbols and evaluating as code

2009-01-25 Thread Christian Vest Hansen
On Sun, Jan 25, 2009 at 11:13 AM, Christophe Grand wrote: > Zak Wilson a écrit : >> know the JVM very well at all. Are there any ways around this? Are >> techniques that generate a lot of short-lived functions just not >> practical in Clojure? >> > Yes there are a way around this: permgen memory

Re: Binding values in a list of symbols and evaluating as code

2009-01-25 Thread Christophe Grand
Zak Wilson a écrit : > Thanks, Christophe. It works now, and it's fast. > > Unfortunately, now I've run in to Nathan's problem. After a few > thousand generations, resulting in the creation of about half a > million functions it was using over a gig of memory and died with an > OutOfMemoryError.

Re: Binding values in a list of symbols and evaluating as code

2009-01-25 Thread Phlex
Phlex wrote: > How about compiling a closure tree ? > > ;; very basic example follows > > (defn make+ [param1 param2] > (fn [environement] > (+ (param1 environement) (param2 environement > > (defn make* [param1 param2] > (fn [environement] > (* (param1 environement) (param2 envir

Re: Binding values in a list of symbols and evaluating as code

2009-01-25 Thread Phlex
How about compiling a closure tree ? ;; very basic example follows (defn make+ [param1 param2] (fn [environement] (+ (param1 environement) (param2 environement (defn make* [param1 param2] (fn [environement] (* (param1 environement) (param2 environement (defn make-variable [

Re: Binding values in a list of symbols and evaluating as code

2009-01-25 Thread Meikel Brandmeyer
Hi, Am 25.01.2009 um 08:41 schrieb Greg Harman: This could be a real problem for Clojure. I can think of other techniques that could easily result in the creation a large number of anonymous functions that ought to get gc'd after a few ms but permanently increase memory usage by a significant a

Re: Binding values in a list of symbols and evaluating as code

2009-01-24 Thread Greg Harman
> This could be a real problem for Clojure. I can think of other > techniques that could easily result in the creation a large number of > anonymous functions that ought to get gc'd after a few ms but > permanently increase memory usage by a significant amount. I don't > know the JVM very well at

Re: Binding values in a list of symbols and evaluating as code

2009-01-24 Thread Zak Wilson
Thanks, Christophe. It works now, and it's fast. Unfortunately, now I've run in to Nathan's problem. After a few thousand generations, resulting in the creation of about half a million functions it was using over a gig of memory and died with an OutOfMemoryError. While let-eval is cool, using it

Re: Binding values in a list of symbols and evaluating as code

2009-01-24 Thread Christophe Grand
You must eval the whole fn form: (defn compile-rule [body] (eval (list `fn '[a b] body))) user=> (let [f (compile-rule '(+ a b))] (f 18 56)) 74 Zak Wilson a écrit : > So as it turns out, I was mistaken about it working. I had something > that ran, but the results were nonsense. What I'm tr

Re: Binding values in a list of symbols and evaluating as code

2009-01-24 Thread Zak Wilson
Correction: it's (let [x '(+ (* 1024 device-id) rave-id)) rfn (rulefn x)] ...) that fails with "Can't eval locals". --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, s

Re: Binding values in a list of symbols and evaluating as code

2009-01-24 Thread Zak Wilson
So as it turns out, I was mistaken about it working. I had something that ran, but the results were nonsense. What I'm trying now looks like this: (defmacro rulefn [r] (let [er (eval r)] `(fn [devid# raveid#] (binding [device-id devid# rave-id raveid#] ~er

Re: Binding values in a list of symbols and evaluating as code

2009-01-23 Thread Nathan Kitchen
On Jan 23, 1:47 pm, Zak Wilson wrote: > And it's now working perfectly, producing a new generation every > second. Now I actually have to tweak it to produce good results. It's great that this is working for you. I tried the same approach in a genetic programming project of my own, and I eventu

Re: Binding values in a list of symbols and evaluating as code

2009-01-23 Thread Zak Wilson
And it's now working perfectly, producing a new generation every second. Now I actually have to tweak it to produce good results. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group,

Re: Binding values in a list of symbols and evaluating as code

2009-01-23 Thread Zak Wilson
Kevin, I don't know how I managed to not think of that, but it's exactly what I was looking for. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegro

Re: Binding values in a list of symbols and evaluating as code

2009-01-23 Thread Jason Wolfe
On Jan 23, 1:18 pm, Kevin Downey wrote: > instead of using binding and eval, you can generate a (fn ) form, eval > it, keep the result function stuffed away somewhere and apply it > instead of calling eval all the time Yeah, when I made this optimization to my code a couple weeks ago it sped the

Re: Binding values in a list of symbols and evaluating as code

2009-01-23 Thread Kevin Downey
instead of using binding and eval, you can generate a (fn ) form, eval it, keep the result function stuffed away somewhere and apply it instead of calling eval all the time On Fri, Jan 23, 2009 at 1:10 PM, Zak Wilson wrote: > > It does seem like a legitimate use for eval, at least at first glanc

Re: Binding values in a list of symbols and evaluating as code

2009-01-23 Thread Zak Wilson
It does seem like a legitimate use for eval, at least at first glance. The biggest problem is that using eval this way is really slow when each rule is being tested on hundreds of inputs. Interesting alternative, Konrad. I can probably take advantage of the fact that all of the functions I'm call

Re: Binding values in a list of symbols and evaluating as code

2009-01-23 Thread Konrad Hinsen
On Jan 23, 2009, at 16:20, Zak Wilson wrote: > that appear in these lists and evaluate them as code. My current > technique looks like this: > > (def a) > (def b) > (defn try-rule [r val-a val-b] >(binding [a val-a > b val-b] > (eval r))) > > and an example call looks

Re: Binding values in a list of symbols and evaluating as code

2009-01-23 Thread Stuart Sierra
Hi Zak, I think this is a reasonable use of eval, since you're evaluating an expression that is generated at run-time. The alternatives are messy. -Stuart Sierra On Jan 23, 10:20 am, Zak Wilson wrote: > I'm trying my hand at genetic programming. (Full post about why and > how, with code comi