tags:

views:

101

answers:

2

After playing a while with quote/unquote, I wanted to do a trick, but it didn't want to be done. Here's what I did and what come out :

user=> (let [x '#(inc 1)] `(1 ~x))
(1 (fn* [] (inc 1)))

But what I wanted was :

(1 2)

Can you help me do that ? :)

And also explain what "part" of Clojure you are using...

+2  A: 

You can use eval:

user=> (let [x `(inc 1)] 
         (eval `(list 1 ~x)))
(1 2)

Or more conventionally:

user=> (defmacro foo [x] 
        `(list 1 ~x))
#'user/foo
user=> (foo (inc 1))
(1 2)
Alex Taggart
+1  A: 

This will work like you want it to:

user> (let [x (#(inc 1))] `(1 ~x))
;=> (1 2)
Hubert
i could just have done this : (let [x (inc 1)] `(1 ~x)), which would mean just evaluate the function before putting it into x. nevertheless, thanks for your idea
Belun