1

I'm having some trouble to get started with Light Table.

Here's my code (Clojure)

(ns prova1-ed.core
  (:gen-class))

(use 'clojure.java.io)

(defn -main [& args]

  (println "Type the name of the file to read: ")

  (let [fileName (read-line)]
    (let [rdr (reader fileName)]
      (doseq [line (line-seq rdr)]
        (println line)
  )))
)

I'm sure it works. I've tested with lein run. As you can see, the program should read a file which the name is given by the user.

I've tried CTRL+SPACE in Light Table, but this is what I receive:

ERROR: Unhandled REPL handler exception processing message {:data {:auto? false, :pos {:line 14, :ch 1}, :mime "text/x-clojure", :tags [:editor.clj :editor.clojure], :type-name "Clojure", :line-ending "\r\n", :ns user, :path "C:\\Users\\Tiago\\Documents\\Clojure\\prova1_ed\\src\\prova1_ed\\core.clj", :print-length nil, :name "core.clj", :local true, :code "(ns prova1-ed.core\n  (:gen-class))\n\n(use 'clojure.java.io)\n\n(defn -main [& args]\n\n  (println \"Type the name of the file to read: \")\n\n  (let [fileName (read-line)]\n    (let [rdr (reader fileName)]\n      (doseq [line (line-seq rdr)]\n        (println line)\n  )))\n)\n"}, :id 90, :op editor.eval.clj.sonar, :session 65d1da68-a730-4ffe-9365-9527726384e3}

Error screen

How can i run it in the Light Tables' enviroment, so that I can input the file name?

Tiago Dall'Oca
  • 329
  • 3
  • 15
  • Are you providing absolute or relative path to your file in LightTable? – Piotrek Bzdyl Apr 24 '16 at 19:10
  • I can't provide anything, because before it the exception is thrown – Tiago Dall'Oca Apr 24 '16 at 23:17
  • How are you executing your code in LightTable? Please, provide detailed steps. – Piotrek Bzdyl Apr 25 '16 at 07:00
  • Aa you can see, I've created the project with Lein. For running it, I press ctrl+enter and the connection with the project is made automatically. But I've also tried to run by making a nrepl connection and connecting to the file project manually. Anyway I can eval simple forms, but not the main function. I'm going to retry what I already done before and see the results. If I achieve any different result I update it here. – Tiago Dall'Oca Apr 25 '16 at 09:06

1 Answers1

1

TLDR

I don't think you can run (read-line) in Light Table as it'd have to add explicit support for allowing input. There's no standard input basically.

An Alternative

I'd suggest you modify your -main function to accept an explicit file-name argument instead of trying to read it from a standard input that isn't available.

I've got a Clojure webapp that I work on in Light Table.

I've got a -main function in a namespace named my-app.web. It looks something like this:

(defn -main [& [port]]
  (let [port (Integer. (or port (env :port) 5000))
        store (cookie/cookie-store {:key (env :session-secret)})]
    (jetty/run-jetty (-> #'secured-app
                         wrap-with-logging
                         wrap-current-user
                         wrap-current-auth
                         wrap-error-page
                         (site {:session {:store store}}))
                     {:port port :join? false})))

In a separate file I've named light-table-start.clj, I've got the following code to run my app inside Light Table:

(require '[my-app.web :as web])
(require '[ring.adapter.jetty :as jetty])

(defonce server (web/-main "5000"))

;; (.start server)
;; (.stop server)

I run the Eval: Eval editor contents command (Ctrl+Shift+Enter on Windows and Linux or +Shift+Enter on Mac OS) the first time I want to run my app (or later, if the connection is closed for some reason). When I want to start or stop the server I can just highlight the code on the respective commented lines and run the Eval: Eval a form in editor command (Ctrl+Enter on Windows and Linux or +Enter on Mac OS).

Kenny Evitt
  • 9,291
  • 5
  • 65
  • 93
  • Thank you! Well, I was expecting a live console like Nightcode's. Do you think it worth changing from LT to Emacs or some other with a console running repl? Or LT sacrifices that and offers others tools that worth the price? – Tiago Dall'Oca Apr 25 '16 at 21:43
  • @TiagoDall'Oca Personally, I don't mind the lack of a console in LT. You can use a regular Clojure file in LT as a REPL, i.e. you can evaluate forms and see their results in the same tab. In fact, the Clojure 'InstaREPL' was recently deprecated because none of the maintainers used it and it didn't really add much beyond the inline eval. – Kenny Evitt Apr 26 '16 at 02:41