• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

REPL and Eclipse

 
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...

 
Rancher
Posts: 379
22
Mac OS X Monad Clojure Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
     
    Greenhorn
    Posts: 12
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Posts: 12
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Rancher
    Posts: 379
    22
    Mac OS X Monad Clojure Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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!
     
    Good night. Drive safely. Here's a tiny ad for the road:
    We need your help - Coderanch server fundraiser
    https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
    reply
      Bookmark Topic Watch Topic
    • New Topic