编译Clojure? [英] Compiling Clojure?

查看:123
本文介绍了编译Clojure?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



目录结构:


$

我在这里感觉有点蠢,但我不能得到Clojure Hello World。 b $ b

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

hello.clj:

 (ns test.hello 
(:gen-class))

(defn -main [& args ]
(printlnHello(nth args 0)))

p>

  $ 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 / -mainthere)
Hello有
nil
user => (编译'test.hello)
java.io.IOException:没有这样的文件或目录(hello.clj:2)
user => * compile-path *
classes
user => (doseq [p(.split(System / getPropertyjava.class.path):)](println p))
./clojure-1.1.0.jar
./build/ classes
./src
nil

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



根据 clojure.org ,编译需求




  • 命名空间必须匹配classpath-相对文件路径 - 检查

  • * compile-path *必须在类路径中 - 检查

  • :ns表单的gen-class参数 - 检查



我发现一年前的这篇文章



我错过了什么?



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

解决方案

a href =http://github.com/technomancy/leiningen =nofollow noreferrer> Leiningen ?使用它,比手动编译代码容易得多。您可以使用我的文章作为简介...


I'm feeling slightly silly here, but I can't get Clojure Hello World to compile.

Directory structure:

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

hello.clj:

(ns test.hello
  (:gen-class))

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

Interaction:

$ 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

So I can load and call the file from the REPL, but it doesn't compile.

According to clojure.org, compilation needs

  • namespace must match classpath-relative file path - check
  • *compile-path* must be on the classpath - check
  • :gen-class argument to the ns form - check

I found this post from a year back, as far as I can tell I'm doing exactly the same, but it doesn't work.

What am I missing?

System: OS X 10.6, Java 1.6.0, Clojure 1.1

解决方案

Why you don't use Leiningen? It's much easier to use it, than compile code manually. You can use my article about it as introduction...

这篇关于编译Clojure?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆