The -main method is for java interop. Together with :gen-class in the ns-operation, it generates a method with the following layout: public static void main(String [ ] args); which correspondents to the java naming convention for the main method.
This generates a .class file and finally a .jar which you can run with: java -cp <path-to-.jar> <ns-of-class> On Sun, Jun 20, 2010 at 6:40 AM, Jared <tri...@gmail.com> wrote: > On Jun 18, 8:43 am, Craig Andera <cand...@wangdera.com> wrote: >> > I'm a little confused over when to use a var vs. a ref vs. an agent >> > vs. an atom. For writing small (<200 lines) single-threaded programs >> > when do I want to use each one? >> >> In addition to the great answers you got here, you could have a look >> at my screencast series on vars, refs, agents, and atoms: >> >> http://link.pluralsight.com/clojure >> >> Ignore the (unfortunate) prominence of the Silverlight player - the >> "mobile" button will give you downloads in all sorts of formats. > > All these links and discussions have been helpful, but especially that > screencast. I've only watched the first two and it has cleared up many > misconceptions I had. > > Do Clojure programs need a main method? The reason I'm asking is > because the default netbeans template writes something similar to > this: > (defn -main [ ] stuff blah-blah) > > Which proceeds to evaluate stuff blah-blah. From experimentation it > seems I don't need a main method to evaluate expression. I can have a > program that is only the namespace delcaration and (println "hi"), and > it runs. It does give me an exception, but it runs. Is this exception > a bad thing? Is using -main a matter of convention? Is -main some sort > of key word, or special phrase? If so why is it -main, and not main? > It seems counterintuitive to define a function just like any other > function using defn, but this function happens to special. > > What is the value of a do block? Specifically in Craig's screencast on > Vars he types up: > (do > (binding [foo "Keith"] > (with-new-thread > (fn [] (print-foo "background: "))) > (print-foo "foreground1 ")) > (print-foo "foreground2: ")) > > If this was written without the do how does it affect the program?: > (binding [foo "Keith"] > (with-new-thread > (fn (print-foo "background: "))) > (print-foo "foreground1: ")) > (print-foo "foreground2: ") > > It might be easier to see this in his video, which would be at 17:13. > > -- > 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 -- Moritz Ulrich Programmer, Student, Almost normal Guy http://www.google.com/profiles/ulrich.moritz -- 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