Reputation: 50007
Newbie to Clojure and Eclipse so please bear with me.
I'm running Clojure 1.5.1 under Eclipse Juno with Counterclockwise (CCW) and Leiningen installed, and I'm testing the process of running Clojure code under the Eclipse debugger. I'm using the following file:
(ns myproject.core)
(defn foo [str]
(println str "Hello, World!")
)
(defn hello [who]
(str "Hello " who "!"))
I set breakpoints on the (println str "Hello, World!")
and (str "Hello " who "!"))
lines, select "myproject" in the Package Explorer pane, click on Run-Debug As-Clojure Application, and a REPL starts up. Now, here's the issue/problem: if I type (hello "Fred")
in the REPL I get
CompilerException java.lang.RuntimeException: Unable to resolve symbol: hello
in this context, compiling:(NO_SOURCE_PATH:1:1)
I get the same error if I try to qualify the procedure call as (myproject.core/hello "Fred")
. The only way I get it to run is to first issue (require 'myproject.core)
and then issue (myproject.core/hello "Fred")
. Once I do this the breakpoints are recognized, the code breaks in the proper place, variables are visible, and life is good.
If I type (use 'myproject.core)
instead of (require 'myproject.core)
I don't have to fully-qualify the function name, but my understanding is that the use of use
is not recommended practice.
On the other hand: if I start the REPL by "sending" the code to the REPL using Ctrl-Alt-S (this is on Windows) I can simply type (hello "Fred")
and get the expected output. Of course, doing it this way does not start the debugger, no breakpoints are taken, etc.
My question: is there a way to run the code under the Eclipse debugger, have the namespace automatically recognized as it is when the code is "sent" to the REPL via Ctrl-Alt-S, not have to use require
or use
, and not have to fully-qualify the function name with the namespace?
Upvotes: 2
Views: 1038
Reputation: 6681
Ctrl-Alt-N is bound to "Switch REPL to File's Namespace" in CCW. The REPL starts in the namespace "user", once you've switched to "myproject.core", there shouldn't be any need to use
or require
anything. You can also switch the namespace with the REPL with in-ns
.
Upvotes: 2