是否可以编译clojure源而无需进入REPL?

vik*_*hal 3 clojure

是否可以编译clojure源而无需进入REPL?如果有一个大项目那么就不可能手动编译每个程序然后制作它的jar文件,就像我希望编译并通过make软件中的一些指令获取类文件一样?

bmi*_*are 7

为了理解这些系统中有多少工作在下面,这里有一些最简单的代码来编译没有repl的代码.

假设您有一些类生成代码:

hello.clj:

 (ns hello
   (:gen-class
    :methods [[sayHi [] String]]))

 (defn -sayHi [this]
   (println "hello world"))
Run Code Online (Sandbox Code Playgroud)

你可以用clojure代码构建你的"makefile"

compile.clj:

 (set! *compile-path* "./")
 (compile 'hello)
Run Code Online (Sandbox Code Playgroud)

然后你只需将代码称为脚本.

 $ java -cp ~/dj/lib/clojure.jar:./ clojure.main compile.clj 
 $ ls
 compile.clj  hello.clj          hello$loading__4505__auto__.class
 hello.class  hello__init.class  hello$_sayHi.class
Run Code Online (Sandbox Code Playgroud)

现在您的代码已编译,您可以像任何其他类文件一样访问它:

 $ java -cp ~/dj/lib/clojure.jar:./ clojure.main
 Clojure 1.3.0
 user=> (import 'hello)
 hello
 user=> (.sayHi (hello.))
 "hello world"
 user=> 
Run Code Online (Sandbox Code Playgroud)