Re: Help with example from "A Field Guide to Genetic Programming"

2009-07-08 Thread Timothy Pratley
> user> (def my-func (list + 1 2)) > #'user/my-func > user> (my-func) A list is not a function. Expanded: ((list + 1 2)) The first item in the outer list is a list, it is not a function. So to invoke the function you need to get it using first. Eval call on a list is evaluating a list, and the fi

Re: Help with example from "A Field Guide to Genetic Programming"

2009-07-08 Thread Richard Newman
> Any expression can be evaluated with eval. As, indeed, can self-evaluating forms: user=> (eval 3) 3 user=> (eval (eval (eval (list + 1 2 3 user=> (eval :foo) :foo user=> (eval '+) # user=> (eval 'eval) # This kind of fiddling around in a REPL is very enlightening. --~--~-~--~--

Re: Help with example from "A Field Guide to Genetic Programming"

2009-07-08 Thread John Harrop
On Wed, Jul 8, 2009 at 1:57 PM, Robert Campbell wrote: > If it's okay, could somebody explain the difference between what's > happening here: > > user> (def my-func (list + 1 2)) > #'user/my-func > user> (my-func) > ; Evaluation aborted. > > and here: > > user> (def my-func (list + 1 2)) > #'user

Re: Help with example from "A Field Guide to Genetic Programming"

2009-07-08 Thread Robert Campbell
That's it, that's exactly what I needed to complete this example. I'm pretty pumped because you guys have shown me a way to do it without macros and without manually managing a quoted tree structure. If it's okay, could somebody explain the difference between what's happening here: user> (def my

Re: Help with example from "A Field Guide to Genetic Programming"

2009-07-08 Thread Richard Newman
> That looks like what I'm after. When I run a test, however, it doesn't > behave properly: You'll want to either eval the expression, or apply the first item in the list to the rest: user=> (eval (list + 1 2)) 3 user=> (let [form (list + 1 2)] (when (not (empty? form)) (apply (first f

Re: Help with example from "A Field Guide to Genetic Programming"

2009-07-08 Thread Robert Campbell
> It seems to me you want: > user=> (list + 1 2) > (# 1 2) That looks like what I'm after. When I run a test, however, it doesn't behave properly: user> (def my-func (list + 1 2)) #'user/my-func user> (my-func) ; Evaluation aborted. clojure.lang.PersistentList cannot be cast to clojure.lang.IFn

Re: Help with example from "A Field Guide to Genetic Programming"

2009-07-07 Thread kyle smith
> I am guessing I need to start reading and using macros at this point? I also wrote something to do symbolic regression. I used plain functions to manipulate quoted trees, and one macro to wrap the expression in a fn and eval. --~--~-~--~~~---~--~~ You received t

Re: Help with example from "A Field Guide to Genetic Programming"

2009-07-07 Thread Timothy Pratley
It seems to me you want: user=> (list + 1 2) (# 1 2) As opposed to: user=> '(+ 1 2) (+ 1 2) Regarding examining a function, contrib has some helpers written by Chris user=> (use 'clojure.contrib.repl-utils) (source func) (show func) In your case source wont be useful as the function is generated

Re: Help with example from "A Field Guide to Genetic Programming"

2009-07-07 Thread Michel Salim
On Jul 7, 8:18 am, Robert Campbell wrote: > 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 pro