I'm trying to write the first basic GP example in this free book: http://www.lulu.com/items/volume_63/2167000/2167025/2/print/book.pdf
I've gotten a lot of the suppor methods working correctly (like fitness) but I'm having problem convering the pseudocode on page 14 for generating random expressions to make up my initial population. Here's what I have so far: (defn gen-rand-expr [functions terminals max-depth arity method] (if (or (= max-depth 0) (and (= method :grow) (< (rand) (/ (count terminals) (+ (count terminals) (count functions)))))) (rand-element terminals) (let [arg1 (gen-rand-expr functions terminals (- max-depth 1) arity method) arg2 (gen-rand-expr functions terminals (- max-depth 1) arity method) func (rand-element functions)] (func arg1 arg2)))) First, how can I print out the definition of a function in clojure? For example, if I do (defn add [x y] (+ x y)) how can inspect this definition, like (show-def add) -> (defn add [x y] (+ x y)). This would help a lot in debugging the random programs I'm trying to generate. Second, I believe the last line is the problem in my code. Let's assume the function randomly selected was +, it will run (+ 1 2) and the entire function returns 3 instead of a randomly generated syntax tree like I need. I then tried '(func arg1 arg2) hoping it would prevent evaluation, but then it will always just return (func arg1 arg2) which isn't what I need either. I need it to actually return a syntax tree made up of expressions like (+ 1 2) but unevaluated. I am guessing I need to start reading and using macros at this point? Rob --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---