On Apr 17, 11:23 pm, "Stephen C. Gilardi" <squee...@mac.com> wrote:
> > I suggest using a "-main" function for this purpose.  Then with
> > (ns ... (:gen-class)) you can generate a static Java class with same
> > behavior.
>
> And if the :gen-class clause renamed main would the main function for  
> this namespace be that named function?

Sure.  This even suggests a process: To "execute" a namespace, first
compile it, then invoke the main() method of the generated class.  We
might try to simplify the compile path stuff first.

> There's currently no way to return a "status" value from an argument  
> with that signature without using System/exit which has the  
> unfortunate side effect of also shutting down the JVM.

True, but the Clojure function can still return a value, if it's being
called interactively.  And if it's not being called interactively,
it's ok to use System/exit.  I frequently do this:

(ns my.cool.namespace (:gen-class))

(defn run [args]
   ... execution code goes here...
   ... return an integer ...)

(defn -main [& args]
  (System/exit (run args)))

>From the REPL, I call "run".  From the command line, I call "java
my.cool.namespace", which invokes "-main", which calls "run".
Different routes, same result.

-Stuart Sierra
--~--~---------~--~----~------------~-------~--~----~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to