views:

36

answers:

1

I need some very basic advice on how to define a working -main function in IntelliJ along the lines of:

(ns clojure.examples.hello
    (:gen-class))

(defn -main
  [greetee]
  (println (str "Hello " greetee "!")))

When I create a project, paste the preceding code in a source file, and set the run configuration (with Script path, module, working dev, and "Run script in REPL" selected), I get :java.lang.Exception: Unable to resolve symbol: -main in this context (NO_SOURCE_FILE:1)" whenever I run (-main "Some Greeting"). Any advice would be helpful.

+2  A: 

I think that La Clojure's REPL starts in the user namespace (as most -- all? -- Clojure REPLs do); you'll have to switch to your project's namespace with (in-ns 'clojure.examples.hello) or (use 'clojure.examples.hello) to call functions defined there. Better yet, (require '[clojure.examples.hello :as hello]) and call them as (hello/-main "IDEA").

Michał Marczyk
Looks like it's a namespace issue and using (in-ns 'clojure.examples.hello) at the REPL command gets me in the proper namespace. IntelliJ chokes on the other commands. Any way to make this more seamless?
Marc
There is no "more seamless" way. If you want to use the code in a particular namespace you need to either be in that namespace or use that namespace. I usually use the namespace so I more closely emulate what it would be like to use that library in another library.
Jeremy Wall
Found more seamless way by using Eclipse for Java and Counterclockwise. Dropping IJ and going with E.
Marc
Happy to hear that you found a satisfactory solution. I use Emacs for Clojure programming myself and wouldn't know how to tame La Clojure. Note that both the `use` and the `require` form should work fine if the directory layout of your project matches the structure of your namespace names and the IDE sets up the classpath properly.
Michał Marczyk
There are more seamless ways. I don't know how CCW or SLIME do it, but VimClojure provides a command to open a repl in the namespace of the current buffer. So no namespace handling required on the user side.
kotarak
Thanks for the replies, Folks. All were useful and I'm going to try every Clojure IDE out to find one that's just right for me. It'll take a lot of research, quite a few apt-gets, and even an occasional apt-get --purge (in anger), but someday I'll find a Clojure IDE setup all my own!!!
Marc