Clojure + Intellij IDEA: stepping through Clojure implementation code

1,498 views
Skip to first unread message

Miron Brezuleanu

unread,
Jan 1, 2010, 5:16:50 PM1/1/10
to clo...@googlegroups.com
Hello,

In order to get a better understanding of how some things happen in Clojure, I'd like to step through Clojure code (and I mean the Java code used to implement Clojure). Basically, just debug a REPL, set breakpoints etc.

Since there's a free version of IDEA, I downloaded it and successfully created an IDEA project out of existing Clojure sources.

Now when I try to get a REPL (by using clojure.main as the startup class), I get an error about clojure/core.clj not being on the classpath. While a very rough solution would be to just move clj/clojure somewhere on the path, I'd like to know how to change the classpath for a module.

I did try playing with the module settings and add a 'library' which has a path to clj/clojure, but I must be doing something wrong, as it doesn't seem to affect the -cp option of the java invocation (I'm checking this using the output window).

Since I am a complete IDEA newbie, I'd be very happy if someone who is using IDEA to work on Clojure can provide a few pointers. I don't mind trying this with Eclipse, so Eclipse advice is welcome too.

Many thanks and Happy New Year everyone,
--
Miron Brezuleanu

Laurent PETIT

unread,
Jan 2, 2010, 8:03:11 AM1/2/10
to clo...@googlegroups.com
Don't know about the current IDEA "La Clojure" clojure plugin status.

But concerning Eclipse (and its counterclockwise plugin), what you
describe here works well AFAIK.

It's also possible to place breakpoints on your own .clj files.

You can quickly start from here :
http://code.google.com/p/counterclockwise/wiki/Documentation#Install_Counterclockwise_plugin

HTH,

--
Laurent

2010/1/1 Miron Brezuleanu <mbr...@gmail.com>:

> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@googlegroups.com
> Note that posts from new members are moderated - please be patient with your
> first post.
> To unsubscribe from this group, send email to
> clojure+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

ianp

unread,
Jan 1, 2010, 11:19:52 PM1/1/10
to Clojure
> Now when I try to get a REPL (by using clojure.main as the startup class), I
> get an error about clojure/core.clj not being on the classpath. While a very
> rough solution would be to just move clj/clojure somewhere on the path, I'd
> like to know how to change the classpath for a module.

Are you using the La Clojure plugin? You can start a REPL console from
the tools menu (Tools ->Clojure REPL -> Add New, bound to CTRL-ALT-A
by default).

If not, the best thing would be to install it:

1. go to File -> Settings
2. select the Plugins section from the list on the left
3. type clojure into the plugin search box
4. select the La Clojure plugin (it'll be under the "available" tab
5. click on the "install" button at the top left of the plugins page

> I did try playing with the module settings and add a 'library' which has a
> path to clj/clojure, but I must be doing something wrong, as it doesn't seem
> to affect the -cp option of the java invocation (I'm checking this using the
> output window).

The REPL that LaClojure gives you will have the same class path as
your clojure project - so you should have both Clojure & Clojure
Contrib available, as well as any libraries that your project has
defined.

Hope this helps!

Cheers,
Ian.

Rich Hickey

unread,
Jan 2, 2010, 12:13:33 PM1/2/10
to clo...@googlegroups.com

I developed Clojure in IntelliJ and still do (the Java part).

In your Run/Debug configuration:

Main class: clojure.main
VM Parameters: -server -cp clojure-slim.jar
Working directory: /wherever/you/put/clojure
Before launch: Run Ant target 'clojure-slim'

This will give you REPL in IntelliJ's IDE. That's not a great REPL,
but will let you walk through Clojure internals. With La Clojure you
can also break in .clj files.

Rich

Ilya Sergey

unread,
Jan 2, 2010, 7:50:52 PM1/2/10
to clo...@googlegroups.com
Hello, Miron.

to debug your Clojure scripts in IntelliJ with the appropriate plugin installed, just create new run configuration for .clj file. It may be created automatically via Ctrl(Meta)-Shift-F10 default shortcut. After this you can run it in REPL mode or as a standalone script  and put breakpoints if you run it in debug mode (Shift-F9 by default).
If you have clojure.jar in one of the libraries you had attached to the module it will be automatically included to the classpath. Normally, when you create a new project clojure.jar is suggested to be downloaded automatically.

With best regards,
Ilya

2010/1/2 Miron Brezuleanu <mbr...@gmail.com>

Miron Brezuleanu

unread,
Jan 3, 2010, 1:29:33 PM1/3/10
to clo...@googlegroups.com
Hi Rich,

On Sat, Jan 2, 2010 at 7:13 PM, Rich Hickey <richh...@gmail.com> wrote:
On Fri, Jan 1, 2010 at 5:16 PM, Miron Brezuleanu <mbr...@gmail.com> wrote:
> Hello,
> In order to get a better understanding of how some things happen in Clojure,
> I'd like to step through Clojure code (and I mean the Java code used to
> implement Clojure). Basically, just debug a REPL, set breakpoints etc.
> Since there's a free version of IDEA, I downloaded it and successfully
> created an IDEA project out of existing Clojure sources.

I developed Clojure in IntelliJ and still do (the Java part).

In your Run/Debug configuration:

Main class: clojure.main
VM Parameters: -server -cp clojure-slim.jar
Working directory: /wherever/you/put/clojure
Before launch: Run Ant target 'clojure-slim'

This will give you REPL in IntelliJ's IDE. That's not a great REPL,
but will let you walk through Clojure internals. With La Clojure you
can also break in .clj files.

Rich

That's exactly the information I needed! Thank you,

--
Miron Brezuleanu

Miron Brezuleanu

unread,
Jan 3, 2010, 1:43:03 PM1/3/10
to clo...@googlegroups.com
Hello,

and thanks everyone for the information.

I have this Visual Studio + ClojureCLR + Emacs (last one to run a REPL in a *shell* buffer) setup that I use to experiment with ClojureCLR. What I do is have the REPL in Emacs, attach to it from Visual Studio, set breakpoints, use Immediate Mode etc. I also need to be able to modify the ClojureCLR code, recompile, restart the REPL, test various things.

I was looking for something similar for Clojure on the JVM, and I think that the setup Rich described is as close to the ClojureCLR setup as it gets.

However, since La Clojure was only a few clicks away after installing IDEA, I also played a little with La Clojure. Some questions:

1) I noticed that stepping into from a Clojure breakpoint takes me to the Java code. I assume that I pop back into Clojure code when reaching an .invoke. Is there a switch to keep "stepping into" Clojure only (kind of fast forwarding on the Java under-the-hood part)?

2) I didn't manage to see values of locals while stopped on a breakpoint in a Clojure function. How is that done? My test was very simple, a hello function (defn hello [greetee] (str "hello " greetee)) and a call to that function. I wanted to see the value of the 'greetee' parameter of the hello function.

3) Is there something similar to Visual Studio's immediate window in IDEA or LaClojure? If there is not, maybe there's a way to integrate the debug repl that was discussed on the list a couple of weeks ago (or something like it) in La Clojure?

Many thanks,
--
Miron Brezuleanu

Reply all
Reply to author
Forward
0 new messages