Created
January 1, 2020 04:53
-
-
Save yellowbean/7bebcd91454aec66171dcc241bf738be to your computer and use it in GitHub Desktop.
complile clojure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
For the sake of understanding how many of these systems work underneath, here is some bare minimum code to compile code without a repl. | |
Say you have some class generating code: | |
hello.clj: | |
(ns hello | |
(:gen-class | |
:methods [[sayHi [] String]])) | |
(defn -sayHi [this] | |
(println "hello world")) | |
You can build your "makefile" out of clojure code | |
compile.clj: | |
(set! *compile-path* "./") | |
(compile 'hello) | |
Then you just call your code as a script. | |
$ 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 | |
Now your code is compiled and you can access it like any other class file: | |
$ java -cp ~/dj/lib/clojure.jar:./ clojure.main | |
Clojure 1.3.0 | |
user=> (import 'hello) | |
hello | |
user=> (.sayHi (hello.)) | |
"hello world" | |
user=> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://stackoverflow.com/questions/7712082/is-it-possible-to-compile-clojure-source-without-going-into-repl