简体   繁体   English

在LightTable中运行leiningen Clojure项目

[英]Running a leiningen Clojure project in LightTable

I'm trying to use Clojure to run my Leiningen project. 我正在尝试使用Clojure来运行我的Leiningen项目。 Even though LightTable says it's connected in the connections pane, it won't execute unless I call the main function manually. 尽管LightTable表示它已在连接窗格中连接,但除非我手动调用main函数,否则它不会执行。

project.clj:

(defproject lein-test "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.5.1"]]
  :main lein-test.core)

core.clj:

(ns lein-test.core)

(defn -main [& args]
  (println "asdf"))

When I eval the entire file with ctrl+shift+enter, I see nil by the ns and nothing in the console. 当我使用ctrl + shift + enter来评估整个文件时,我在ns看到nil ,控制台中没有任何内容。 If I add 如果我加

(-main)

then the console shows 'asdf'. 然后控制台显示'asdf'。 lein run in the command prompt yields the expected behavior. lein run在命令提示符下lein run产生预期的行为。 What am I missing? 我错过了什么?

Control+Shift+Enter evaluates the namespace. Control + Shift + Enter评估命名空间。

Evaluating a namespace should not run any of its functions, unless you call them at the top level. 评估命名空间不应该运行任何函数,除非您在顶层调用它们。 In a given codebase there should ideally be only one function that is called at the top level (conventionally, the -main function), and one should set this up not by calling it in the namespace code, but as you have, via configuration. 在给定的代码库中,理想情况下应该只有一个在顶层调用的函数(通常是-main函数),并且应该通过在命名空间代码中调用它来设置它,而不是通过配置来调用它。

Everything is working as expected here. 一切都在这里按预期工作。 You can put a call to (-main) in a commented block or a temporary section of the file for convenience while developing, or call it directly from the repl interface. 为了方便起见,您可以在注释块或文件的临时部分中调用(-main),或直接从repl接口调用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM