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 <zak.wil...@gmail.com> wrote:
> I'm trying my hand at genetic programming. (Full post about why and
> how, with code coming soon - I promise.) My current technique uses a
> genetic algorithm to generate a list of symbols, numbers and other
> lists of the same form. The head is the name of any of several
> functions. I'm trying to figure out a good way to bind the symbols
> 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 like:
> (try-rule '(+ a b) 2 4)
>
> I know that calls to eval are discouraged outside of writing something
> like a REPL. I'm looking for a better way to do this. Note that
> binding a and b when the rules are generated or using actual values
> instead of symbols won't work because each rule actually needs to be
> tested against hundreds of possible values.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to