> It seems to me you want:
> user=> (list + 1 2)
> (#<core$_PLUS___4006 clojure.core$_plus___4...@1acd47> 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




On Wed, Jul 8, 2009 at 6:06 AM, Timothy Pratley<timothyprat...@gmail.com> wrote:
>
> It seems to me you want:
> user=> (list + 1 2)
> (#<core$_PLUS___4006 clojure.core$_plus___4...@1acd47> 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 not
> read from source. The output from show is a bit opaque to me so not
> sure if it is useful to you.
>
> I think once it is compiled a function is not easy to examine... so as
> you alluded to the best alternative would be to keep the AST?
>
> Regards,
> Tim.
>
> On Jul 7, 10:18 pm, Robert Campbell <rrc...@gmail.com> wrote:
>> 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to