4

I'm learning clojure on eclipse (counterclockwise plugin).

  • When I click "run" in eclipse (as I would do with Java) I get not only the console opened but this "REPL" window. Why is it necessary and what does it do?
  • When I click "run" it takes quite a few seconds to launch the app. Is there a way to make it faster?
  • When I need to edit the code and relaunch (run) the the app I'm getting this message: "The selection cannot be launched, and there are no recent launches". What is that and why wouldn't it let me relaunch my code? If I wait a while I can launch it again.

This is simple bit of code that I'm trying to run:

(ns ClojureTest.core)

(let [input (read-line)]
  (if (= "x" input)
    (do
      (println "Exit")
      (System/exit 0)
    )
    (do
      (println input)
      (recur)
    )
  )
)

UPDATE: I managed to screw it up even further. Now when I click "Run" the console ignores any input as if the application wasn't even running...

UPDATE2 I've restarted eclipse and the previous problem was solved. Now I can run the app in the console again. I have no idea what happened. The only difference I can see is that when I messed it up - the REPL window title looked like this:

REPL @ nrepl://127.0.0.1:60429 (user)

And after restarting eclipse it came back to this:

REPL @ nrepl://127.0.0.1:60001 (ClojureTest.core)

I have no idea what this means.

Caballero
  • 11,546
  • 22
  • 103
  • 163

1 Answers1

2

You only need one open REPL per project. Once opened, you can evaluate changed code from an existing file (namespace), by choosing so from the Clojure menu. The selection or entire file, depending on what you choose, is then sent to the REPL for evaluation. You can try out your changes immediately by calling functions from the REPL. This is called interactive development. There is no need to recompile your entire project, before you can try out changes.

The developers of CCW just chose the action for the Run button to be 'open a REPL for the existing project'. Use it only once and don't keep pressing it, while developing.

Michiel Borkent
  • 34,228
  • 15
  • 86
  • 149
  • Thanks for your answer, I thought something like that, but it's totally confusing. I need it to clear the console and relaunch the application - I've tried every single item from Clojure menu - none of them seem to do that. – Caballero Sep 15 '13 at 12:28
  • You'd have to kill the console and the REPL. – Michiel Borkent Sep 15 '13 at 14:49
  • I admit it can be confusing. It's best to just use the Clojure menu if you don't want surprises. – Michiel Borkent Sep 15 '13 at 14:49
  • So still, every time I edit the code I need to relaunch the REPL. I don't understand how someone can develop in this language. There is nothing in Clojure menu that can help with this. – Caballero Sep 15 '13 at 15:22
  • That is exactly the opposite of what I was saying in my answer. You only submit the changes to the REPL, not relaunch anything. This is a main difference between Clojure and other languages that require a monolithic edit/compile/run-cycle. In Clojure you can redefine almost everything at run time. – Michiel Borkent Sep 15 '13 at 16:03
  • The code snippet above - I can edit it as much as I want - nothing changes unless I restart REPL. So how exactly does that re-evaluation work? – Caballero Sep 15 '13 at 16:09
  • @Caballero Select the snippet, go to the Clojure menu and press "Evaluate current selection or Top-Level S-Expression" – Michiel Borkent Sep 15 '13 at 16:14
  • I've tried that - it gives me "Input required" popup, but I need to do that in the console. Surely there has to be a way of running the application in the console. – Caballero Sep 15 '13 at 16:20
  • When I evaluate (read-line) from the REPL, I get an "Input requested" popup, I fill in some text and it is the result of the function call as a string, which will be printed in the REPL. – Michiel Borkent Sep 15 '13 at 16:30
  • I am starting to sense that with Console you don't mean the Eclipse console. Yes, you can run your project from a terminal window, if that is what you mean. You need leiningen installed for it and just type 'lein run' from the project's directory. CCW just allows you to input via a Window by convenience. See leiningen.org for more detail. If you decide to deploy your project as an uberjar, you don't need leiningen anymore. – Michiel Borkent Sep 15 '13 at 16:33
  • Sorry, I meant eclipse console - the one that sits next to REPL window – Caballero Sep 15 '13 at 16:39
  • Then you should type input in the popup window. – Michiel Borkent Sep 15 '13 at 17:21