【发布时间】:2014-05-18 00:06:59
【问题描述】:
我刚开始使用 lein 进行我的第一个 clojure 项目,代码在这里:
(ns fileops.core
(:use
[clojure.core :only (slurp)]
[clojure-csv.core :only (parse-csv)]
[fileops.core]))
(defn -main
"I don't do a whole lot ... yet."
[& args]
(read-file "sample.csv"))
(defn read-file
"open and read the csv file"
[fname]
(with-open [file (clojure.java.io/reader fname)]
(parse-csv (slurp fname))))
我尝试使用“lein run”运行它,但我不断收到此错误:
Caused by: java.lang.RuntimeException: Unable to resolve symbol: read-file in this context
at clojure.lang.Util.runtimeException(Util.java:219)
at clojure.lang.Compiler.resolveIn(Compiler.java:6874)
at clojure.lang.Compiler.resolve(Compiler.java:6818)
at clojure.lang.Compiler.analyzeSymbol(Compiler.java:6779)
at clojure.lang.Compiler.analyze(Compiler.java:6343)
... 52 more
我做错了什么?
【问题讨论】:
-
read-file 应该在源代码中的 main 之前。
-
@DiegoBasch 你是救生员。我是 Clojure 的新手,我花了太多时间试图弄清楚为什么我收到关于在错误上下文中调用我的函数的错误。就是这样……一直都是这样。很棒的帖子。
标签: clojure