开发者

How to force evaluate?

开发者 https://www.devze.com 2023-01-16 01:42 出处:网络
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 :

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)] `(开发者_C百科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...


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)


This will work like you want it to:

user> (let [x (#(inc 1))] `(1 ~x))
;=> (1 2)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号