aspose file tools*
The moose likes Clojure and the fly likes REPL and Eclipse Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Clojure
Bookmark "REPL and Eclipse " Watch "REPL and Eclipse " New topic
Author

REPL and Eclipse

jay vas
Ranch Hand

Joined: Aug 30, 2005
Posts: 407
hi guys , Im trying to setup a "rapid" testing environment with REPL and eclipse.

Eclipse allows you to run REPL, but im not sure how to "reload" my clojure script in the eclipse REPL environment.

how can I get the eclipse REPL console for the clojure plugin to reload a script ?

I heard that one of the main advantages of clojure is the dynamic reloadability..... and I wanted to experiment with that...

Sean Corfield
Ranch Hand

Joined: Feb 09, 2011
Posts: 267
    
    5

Since you're working with Eclipse, I assume you've installed Counter Clockwise, the Clojure plugin?

Here's my workflow:
  • Use Leiningen at the command line to create a new Clojure project
  • In that project folder, run: lein deps
  • In Eclipse, create a Java project based on that folder
  • Right-click on the project and Enable Clojure Support

  • Now you should be able to right-click on the project and Run As... Clojure Application.

    This will start a REPL window. If it says there are errors in the build path, right-click on the project and (re-)configure the Build Path (either under Properties or Build Path... depending on your version of Eclipse and/or which perspective you're in). You need to update the Build Path whenever you add dependencies to your project.

    Open a Clojure source file and then look at the Clojure menu to see what the shortcuts are for Load File in REPL, Switch REPL to File's Namespace, and Evaluate current selection..

    These are different between Mac and Ubuntu. Not sure about Windows (I don't use that).

    Now you can write code, Load File in REPL, Switch REPL to File's Namespace (which also puts the cursor in the REPL) and then run code. Ctl-Up / Down arrow should cycle thru the REPL history so you can retrieve stuff to copy and paste back into your source editor.

    My workflow is usually to work mostly in the REPL as I evolve a function piece by piece (it's useful to know that *1 is bound to the last REPL result, *2 to the previous one, so you can apply functions repeatedly to the previous results). As I get each little piece working the way I want, I copy it into a function in the source code and maybe flesh it out a little more, then Load File in REPL, Switch... and go back to working in the REPL.

    Since I tend to write tests a lot, it's particularly nice to be able to copy some pieces of code into my test files and then I can easily run those with Load File, Switch... and evaluate (run-tests).

    If you're not using Leiningen, you can skip the first two bullets and just create a new Java project and Enable Clojure Support. CCW will add clojure.jar to your project (you may have to add it to the build path).

    Hope that helps?
    Ned Bakelman
    Greenhorn

    Joined: Nov 25, 2011
    Posts: 12
    Hello Sean,

    I'm brand new to Clojure (gulp) and installed the counter clockwise plugin for Eclipse. I can launch a REPL window from within Eclipse, but I don't get any prompts within the window (meaning there's no "=>"). When I first launch the REPL from within Eclipse the only thing I see is ";; Clojure 1.2.0", but again no place to enter anything in.

    I'm wondering if this is related to the question you responded to. Do I need to use "Leiningen" in order to get this functionality?

    Not sure what Leiningen is, but I'll investigate. Any help would be greatly appreciated.

    Happy Thanksgiving

    Ned
    Ned Bakelman
    Greenhorn

    Joined: Nov 25, 2011
    Posts: 12
    Please ignore my last question about the REPL prompt. Apparently there was a modification made to recent versions of Counter Clockwise where it is now required to press "Ctrl + Enter" to send any command to the REPL server. Here's the link: Prompt in REPL Window

    I pulled my hair out over this one for a few days, don't want to see that happen to anybody else

    Thanks

    Ned
    Sean Corfield
    Ranch Hand

    Joined: Feb 09, 2011
    Posts: 267
        
        5

    Just so folks know why: the CCW REPL has full structural editing, just like in the main editor - so enter inserts a newline and indents code. Unless you are at the end of a complete top-level form. You used to have to press shift-cmd-x (I think? at least on Mac OS X) to submit code when you were in the middle of a form - the shortcut for execute current form under the cursor when you're in the main editor. ctl-enter is a nicer shortcut key for submitting code and it's more consistent to make enter always behave like the editor and ctl-enter always submit the entire form. This may seem odd if you're not used to the strict structural editing mode - which I set as the default, as do most Clojurians - since this matches paredit in Emacs. Once you get used to paredit / strict structural mode, you'll never go back!
     
     
    subject: REPL and Eclipse