Clojure compiles sources to Java ".class" files. To create a .class file that can be run at the command line, you need a namespace with a (:gen-class) directive and a function named "-main". Here's an example:
(ns com.example.myapp (:gen-class)) (defn -main [] (println "Hello, World!")) This would go in a file named src/com/example/myapp.clj To compile it, you would run the following commands: mkdir classes java -cp src:classes:clojure.jar clojure.lang.Compile com.example.myapp Then you can execute it with the command: java -cp classes:clojure.jar com.example.myapp In general, this process is made easier by build tools such as Leiningen and clojure-maven-plugin; consult those tools' documentation for more information. -S On Sep 5, 12:46 pm, CuppoJava <patrickli_2...@hotmail.com> wrote: > Hi everyone, > I'm writing a simple lisp for educational purposes, and I can't figure > out how to do compilation. In particular, I can't figure out how I can > get a compiled file to run in the same way as if it were loaded. I > read on the webpage that Clojure can do this. Does anyone know how > Clojure does it? > > eg. How can I compile this file, such that it does the same thing as > when it's loaded: > > (def macro-helper (atom nil)) > > (println "Setting Macrohelper!") > (swap! macro-helper > (constantly (fn [] > (println "Macro-Helper!") > `(println "Runtime!")))) > > (defmacro mymacro [] > (println "Macro Expansion Time!") > (@macro-helper)) > > (mymacro) > > Thanks a lot! > -Patrick -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en