clojure - 编译Clojure?

标签 clojure compilation

我在这里感觉有点傻,但我无法编译 Clojure Hello World。

目录结构:

hello-world/
  clojure-1.1.0.jar
  build/
    classes/
  src/
    test/
      hello.clj

你好.clj:
(ns test.hello
  (:gen-class))

(defn -main [& args]
  (println "Hello" (nth args 0)))

相互作用:
$ cd hello-world
[hello-world]$ java -cp ./clojure-1.1.0.jar:./build/classes:./src clojure.main
Clojure 1.1.0
user=> (require 'test.hello)
nil
user=> (test.hello/-main "there")
Hello there
nil
user=> (compile 'test.hello)
java.io.IOException: No such file or directory (hello.clj:2)
user=> *compile-path*
"classes"
user=> (doseq [p (.split (System/getProperty "java.class.path") ":")] (println p))
./clojure-1.1.0.jar
./build/classes
./src
nil

所以我可以从 REPL 加载和调用文件,但它不能编译。

根据 clojure.org ,编译需要
  • 命名空间必须与类路径相关的文件路径匹配 - 检查
  • *compile-path* 必须在类路径上 - 检查
  • ns 形式的 :gen-class 参数 - 检查

  • 我找到了 this post from a year back ,据我所知,我正在做完全相同的事情,但它不起作用。

    我错过了什么?

    系统:OS X 10.6、Java 1.6.0、Clojure 1.1

    最佳答案

    明白了,还有第四个要求:

  • *compile-path* 是相对于 JVM 工作目录解析的,通常是启动 java 的目录。或者通过 REPL:(System/getProperty "user.dir") ,

  • 所以这有效:
    user=> (set! *compile-path* "build/classes")     
    "build/classes"
    user=> (compile 'test.hello)
    test.hello
    

    关于clojure - 编译Clojure?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3123662/

    相关文章:

    Clojure:使用 assoc-in 的结果不一致

    clojure - 为什么 Clojure defmulti 调度函数接收 0 个参数?

    clojure.tools.namespace.repl/refresh 不起作用

    clojure - 获取调用表单的 namespace

    clojure - the -> 宏和偏函数

    c++ - 如何使用 html tidy C++ 编译 C++ 程序

    c++ - 为什么我的 .cpp 文件没有被处理?

    ios - 快速读取 JSON 解析到 NSArray 时出现段错误

    javascript - Processing.js 和 JavaScript 语法

    android - 从命令行编译Android项目很慢