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