On Jul 7, 8:18 am, Robert Campbell <rrc...@gmail.com> 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 programs I'm trying to
> generate.
>
I don't think that's possible. You can use (doc add), which will give
you the arity signatures of add, as well as the documentation for add,
if there was any. You could, I suppose, include the function body
itself in its documentation, e.g.:

(defn add "(+ x y)" [x y] (+ x y))
#'user/add
user=> (doc add)
-------------------------
user/add
([x y])
  (+ x y)
nil

> 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.
>
If your syntax tree is just composed of three-element lists, then
instead of your definition of add, you might want this:

(defn add [x y] `(+ ~x ~y))

HTH,

--
Michel
--~--~---------~--~----~------------~-------~--~----~
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