4

I'm trying to use Clojure to run my Leiningen project. Even though LightTable says it's connected in the connections pane, it won't execute unless I call the main function manually.

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. If I add

(-main)

then the console shows 'asdf'. lein run in the command prompt yields the expected behavior. What am I missing?

Rob Lourens
  • 15,081
  • 5
  • 76
  • 91

1 Answers1

6

Control+Shift+Enter evaluates the namespace.

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.

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.

noisesmith
  • 20,076
  • 2
  • 41
  • 49
  • Ok. So there is no 'lein run' equivalent in Light Table? How about 'lein test'? – Rob Lourens Jan 20 '14 at 05:01
  • Light table is not my main editor, so there may be info out there I am not finding, but surprisingly I don't see anything other than an indication from the author that a plugin would be the right way to do clojure.test integration, I see no indication that said plugin exists. A workaround would be to load all the namespaces defining tests and manually running `(clojure.test/run-all-tests)` in a repl. – noisesmith Jan 20 '14 at 05:07
  • Edit: [here is info on the level of integrations that exists](https://github.com/LightTable/LightTable/issues/114) – noisesmith Jan 20 '14 at 05:20
  • 1
    Perfect, that's the info I need. Thanks. – Rob Lourens Jan 20 '14 at 05:26
  • Thank you. And cmd-shift-enter on mac. – kometen Jan 03 '17 at 09:36