代码之家  ›  专栏  ›  技术社区  ›  Marc

在IntelliJ中定义Clojure-main函数

  •  8
  • Marc  · 技术社区  · 14 年前

    (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") . 任何建议都会有帮助。

    1 回复  |  直到 14 年前
        1
  •  5
  •   Michał Marczyk    14 年前

    我认为La Clojure的REPL始于 user 名称空间(如大多数--全部?--Clojure REPLs do)公司;您必须使用 (in-ns 'clojure.examples.hello) (use 'clojure.examples.hello) 调用此处定义的函数。更好的是, (require '[clojure.examples.hello :as hello]) (hello/-main "IDEA") .