将列表评估为Clojure的出租对象 [英] eval a list into a let on clojure
问题描述
下一个是我的问题,我尝试使用let将值分配给这些变量来评估包含一些变量的列表
My problem is the next, i try to evaluate a list with some vars using a let to asign values to this vars
如果我做(def a (list * 'x 'y))
和(let [x 3 y 3] (eval a))
,我有一个
CompilerException java.lang.RuntimeException:无法解析符号:x在这种情况下,编译:(NO_SOURCE_PATH:6)
if i do (def a (list * 'x 'y))
and (let [x 3 y 3] (eval a))
I have a
CompilerException java.lang.RuntimeException: Unable to resolve symbol: x in this context, compiling:(NO_SOURCE_PATH:6)
但是如果我跑步
(def x 4) (def y 4)
和(eval a)
我有16,反正如果我再次运行(let [x 3 y 3] (eval a))
我有16,
but if I run
(def x 4) (def y 4)
and (eval a)
i have a 16, anyway if I run again (let [x 3 y 3] (eval a))
again I have 16,
是否存在正确绑定x和y并评估列表的方法?
exist a method to binding the x and y correctly and eval the list?
ty!
推荐答案
好吧,您还可以eval
let
表达式,看看这是否是您需要的:
Well, you could also eval
the let
expression, See if this is what you need:
(eval '(let [x 3 y 3] (* x y)))
根据评论,这将适合您的情况:
According to the comments, this will work for your case:
(def a (list (list * 'x 'y)))
(eval (concat '(let [x 3 y 3]) a))
更好的是,使用准引用:
Even better, use quasiquoting:
(def a (list * 'x 'y))
(eval `(let ~'[x 3 y 3] ~a))
这篇关于将列表评估为Clojure的出租对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!