【问题标题】:Simple clojure program doesn't work简单的clojure程序不起作用
【发布时间】:2014-01-31 20:45:34
【问题描述】:

我正在尝试遵循 Clojure Data Analasys Cookbook 中的示例。我正在使用 LightTable 来玩这个程序。第一个例子展示了如何读入 .csv 数据。

我使用了 lein new getting-data。然后我将这两个依赖项添加到项目文件中

  (defproject getting-data "0.1.0-SNAPSHOT"

  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [
                  [org.clojure/clojure "1.5.1"]
                  [incanter/incanter-core "1.4.1"]
                  [incanter/incanter-io "1.4.1"]
                ]
  )

然后在 core.clj 文件中我说如下,在 LightTable 中使用 cmd-shift-enter 来评估程序,但我得到了这些异常:

(use 'incanter.core 'incanter.io)

clojure.lang.Compiler$CompilerException:java.lang.RuntimeException:无法解析符号:在此上下文中使用,正在编译:(/Users/idf/Documents/clojure/getting-data/src/getting_data/core.clj :1:1)

(read-dataset "data/small-sample.csv") 

clojure.lang.Compiler$CompilerException: java.lang.RuntimeException: Unable to resolve symbol: read-dataset in this context, 编译:(/Users/idf/Documents/clojure/getting-data/src/getting_data/core .clj:4:1)

不确定我做错了什么?

【问题讨论】:

  • 你能展示你的整个 project.clj 吗?
  • 刚刚编辑了帖子。
  • 你是如何评估/编译表达式的?
  • 顺便说一句,您的 project.clj 看起来不错。
  • 参见上面的重写。我正在使用 LightTable,使用 cmd-shift-enter

标签: clojure lighttable


【解决方案1】:

“无法解析符号:在此上下文中使用”意味着光表环境基本上无法评估任何东西:没有任何与咒术相关的问题。不使用 light table,我无法就修复它提供进一步的建议,但看起来你不知何故进入了一个没有 clojure.core 引用的命名空间。如果您在实际想要运行的其余代码之前(clojure.core/refer 'clojure.core),它应该可以工作,但当然这不是必需的。

【讨论】:

    【解决方案2】:

    输入你的代码

    (ns getting-data.core)
    (use 'incanter.core 'incanter.io)
    (read-dataset "data/small-sample.csv") 
    

    在生成的 core.clj 文件中移到那里并按 strg-enter。现在它应该评估编辑器中的所有内容。或者打开项目并打开一个 Instarepl,LightTable 应该会询问您 repl 应该挂接到哪个项目。

    问候 弗里克

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-03-03
      • 1970-01-01
      • 1970-01-01
      • 2018-10-05
      • 1970-01-01
      • 1970-01-01
      • 2013-05-09
      相关资源
      最近更新 更多