在IntelliJ中定义Clojure -main函数

Mar*_*arc 8 program-entry-point clojure intellij-idea

我需要一些关于如何在IntelliJ中定义工作域函数的非常基本的建议:

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

(defn -main
  [greetee]
  (println (str "Hello " greetee "!")))
Run Code Online (Sandbox Code Playgroud)

当我创建一个项目时,将前面的代码粘贴到源文件中,并设置运行配置(选择脚本路径,模块,工作开发和"在REPL中运行脚本"),:java.lang.Exception: Unable to resolve symbol: -main in this context (NO_SOURCE_FILE:1)"每次运行时都会得到(-main "Some Greeting").任何意见将是有益的.

Mic*_*zyk 5

我认为La Clojure的REPL从user命名空间开始(大多数 - 所有? - Clojure REPL都这样做); 你必须用(in-ns 'clojure.examples.hello)(use 'clojure.examples.hello)调用那里定义的函数来切换到项目的命名空间.更好的是,(require '[clojure.examples.hello :as hello])并称之为(hello/-main "IDEA").