我有问题EVAL-ING通过Deriva返回LazySeq:Clojure的EVAL用数学函数
(use 'clojure.core.matrix)
(use 'com.lambder.deriva.core)
(def f1 '(cos (* x y)))
(def f2 '(sin (* x y)))
(def f [f1 f2])
(def u ['x 'y])
(def x 4)
(def y 3)
(defn jacobian [f u]
(map #(partial-derivative f %) u)
)
返回LazySeq
((vector (* (* -1 (sin (* x y))) y) (* (cos (* x y)) y)) (vector (* (* -1 (sin (* x y))) x) (* (cos (* x y)) x)))
哪些可以使用REPL成功EVAL-ED:
(eval (into [] (jacobian f u)))
结果在正确的矩阵
[[1.609718754001305 2.5315618761974763] [2.1462916720017398 3.3754158349299686]]
如果我把EVAL的CLJ文件内lein run
(defn -main
[]
(eval (into [] (jacobian f u)))
)
我得到了不同的命名空间Exception in thread "main" java.lang.RuntimeException: Unable to resolve symbol: sin in this context, compiling:(/tmp/form-init2786363415298022761.clj:1:113)
因为eval
作品。
有什么办法可以将clojure.math函数包含在由eval生成的临时名称空间中吗?还是有更好的方法来评估表达?