9

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

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

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

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

4

1 回答 1

6

我认为 La Clojure 的 REPL 从user命名空间开始(就像大多数 - 所有? - Clojure REPL 一样);您必须使用(in-ns 'clojure.examples.hello)(use 'clojure.examples.hello)调用那里定义的函数切换到项目的命名空间。更好的是,(require '[clojure.examples.hello :as hello])将它们称为(hello/-main "IDEA").

于 2010-07-12T00:21:51.640 回答