我在 clojure 文件中有以下内容:
(ns helloworld
(:gen-class
:main -main))
(defn hello-world-fn []
(println "Hello World"))
(defn -main [& args]
(eval (read-string "(hello-world-fn)")))
我正在运行它
lein run helloworld
我收到以下错误:
Exception in thread "main" java.lang.RuntimeException: Unable to resolve symbol:
helloworld in this context, compiling:(helloworld.clj:12)
我有一种感觉,我需要做点什么ns-resolve
or resolve
但我还没有取得任何成功。我在主函数中尝试了以下操作:
(let [call-string (read-string "(hello-world-fn)")
func (resolve (symbol (first call-string)))
args (rest call-string)]
(apply func args))
没有成功。
有人可以 (a) 为我指明正确的方向吗? (b) 准确解释发生这种情况时 Clojure 阅读器中发生了什么?
尝试查看您的实际名称空间-main
.
(defn -main [& args]
(prn *ns*)
(eval (read-string "(hello-world-fn)")))
它输出#<Namespace user>
在轰炸之前例外。这暗示程序的执行lein run
开始于user
命名空间,它显然不包含您的映射hello-world-fn
象征。您需要明确限定它。
(defn -main [& args]
(eval (read-string "(helloworld/hello-world-fn)")))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)