Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Defining Clojure -main function in IntelliJ

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.

like image 900
Marc Avatar asked Jul 12 '10 00:07

Marc


1 Answers

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").

like image 190
Michał Marczyk Avatar answered Nov 07 '22 13:11

Michał Marczyk