On Nov 17, 8:50 am, "Stephen C. Gilardi" <[EMAIL PROTECTED]> wrote:
> On Nov 16, 2008, at 10:34 PM, Rich Hickey wrote:
>
> > Since it only requires main, might I suggest you write this in
> > Clojure instead?
>
> I gave that a try.
>
> Here's a simple version of a driver for the compiler, stored in src/
> clj/clojure/compile.clj:
>
> (ns clojure.compile)
>
> (defn main
> "Compiles libs into class files stored at compile-path.
> All args are strings"
> [compile-path & libs]
> (printf "Compiling %d libs to %s\n" (count libs) compile-path)
> (flush)
> (binding [*compile-path* compile-path]
> (doseq [lib libs]
> (compile (symbol lib)))))
>
> It works when run from within the Clojure repl:
>
> % ls build/classes/clojure/hello*
> ls: build/classes/clojure/*hello*: No such file or directory
> % java -cp clojure.jar:src/clj/ clojure.lang.Repl
> Clojure
> user=> (require 'clojure.compile)
> nil
> user=> (clojure.compile/main "build/classes" "clojure.hello")
> Compiling 1 libs to build/classes
> nil
> user=>
> % ls build/classes/clojure/hello*
> build/classes/clojure/hello$main__8.class build/classes/clojure/
> hello.class
>
> but when run as a standalone main, it gives an exception that appears
> to be related to static initializers:
>
> % java -cp clojure.jar:src/clj/ clojure.compile build/classes
> clojure.hello
> Compiling 1 libs to build/classes
> Exception in thread "main" java.lang.IllegalStateException: Var null/
> null is unbound. (hello.clj:3)
> For reference, here is the test compilee: src/clj/clojure/hello.clj:
>
> (ns clojure.hello)
>
> (defn main
> [greetee]
> (printf "Hello, %s wow\n" greetee)
> (flush))
>
> I'd appreciate help in getting a standalone invocation of something
> like compile.clj above (i.e., using it's own main without Repl or
> Script) to work.
>
I think you've got some of the interim work I've done integrating gen-
class. main now needs to be called -main, as all methods will be
defined with leading -.
> In working through this, I also found that a compiler driver written
> in Java may be preferable for use via build.xml because of a bootstrap
> problem. Until we compile (something like) "compile.clj", we can't
> call it as a standalone main. (One could add a step that builds the
> compiler driver via a clojure.lang.Script invocation.)
>
Good point. This may just be an exercise then.
Rich
--~--~---------~--~----~------------~-------~--~----~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---