In LightTable, how do you change Clojure version? - clojure

Currently I am using LightTable to run clojure projects, and with Leiningen I can specify a version for a project. However, for .clj files that are not part of a project, it seems the LightTable REPL says the clojure version is 1.5.1.
I would like to set it to 1.7.0 for all .clj files, is there a way to do this?

It is described in LightTable FAQ:
How do I set the default Clojure version when running Instarepl outside of the context of a Clojure project?
Update plugins/clojure/runner/resources/project.clj by adding/changing :dependencies [[org.clojure/clojure "x.x.x" ]] where x.x.x is of course the Clojure version you want to use by default in your Instarepl sessions whenever LightTable doesn't run in the context of a Clojure project (i.e. double clicking on a shortcut on the desktop to run LightTable).
Per http://docs.lighttable.com/#plugins-directory, running the command App: Light Table version to get plugin directory.

Related

Is there a better way to debug clojure code?

I've been working with Clojure for few weeks now, primarily with Lein+Luminus framework. I've been looking for a way to debug code while on the REPL.
I really like the way how pry(on Ruby) works, when it comes to debugging and runtime invocation. Is there an equivalent to pry for clojure code? or probably a technique/tool that I've missed?
There are two paths to consider to improve your REPL and debugging experience:
Using a REPL and debugger integrated with your editor or IDE of choice
Using an embedded nREPL server
The first is an essential part of setting up your local Clojure development environment and should be done regardless. The second option, using an embedded nREPL server, is closer in usage to how you would use a binding.pry call in your code since it gives you access to the running application, but it isn't used to stop execution at a certain point, but rather give you a REPL with access to your running application and it doesn't provide any additional debugging features on its own.
Editor/IDE with REPL and Debugger
Text editors like Emacs and Vim have excellent Clojure support (both for editing and interacting with a REPL), and most Java IDE's have Clojure support as well.
At this point (May 2015) I'd highly recommend trying Jetbrain's Intellij IDEA with the Cursive plugin because of its excellent support for debugging. You can use the free community edition of Intellij, and the Cursive plugin is (at this point) free as well.
Intellij IDEA
To install Cursive, you go into Intellij's settings, add the correct Cursive plugin repository for the version of Intellij you have, install Cursive, and restart the IDE.
Once Cursive is active, you can simply open an existing Leiningen project in Intellij via "File > Open...". To get a REPL running, click "Run > Edit Configurations" in the main menu. In the window that appears, click the "+" button at the top left and select "Clojure REPL > Local". I'd change the name of the run configuration from "Unnamed" to something like "REPL", but otherwise keep the defaults and press "OK" to save the run configuration.
Now you have a way to run a REPL set up for the project you've opened. You can now click "Run > Run 'REPL'" (or whatever you named that run configuration) for a normal REPL, or better yet click "Run > Debug 'REPL'" to boot up the REPL in a debug mode that allows you to use Intellij's debugging features to debug your Clojure code. Set break points, add breakpoint conditions, run code and inspect frames, variables, etc., like you would in any debugger.
In your case, you'd want to click "Run > Debug 'REPL'" and then execute in that REPL the code you use to boot up your application.
Embedded nREPL Server
The above approach assumes that you first start a Clojure REPL and then boot up your application. If instead you want to have your application boot up normally and then optionally get a REPL that lives inside the running Clojure program, using nREPL directly is your best option.
From its own README:
nREPL is a Clojure network REPL that provides a REPL server and client, along with some common APIs of use to IDEs and other tools that may need to evaluate Clojure code in remote environments.
You should follow these instructions to add a running nREPL server to your application, but here is the most important part:
=> (use '[clojure.tools.nrepl.server :only (start-server stop-server)])
nil
=> (defonce server (start-server :port 7888))
#'user/server
Once you have a running nREPL server as part of your Clojure application, you can attach to it using your editor or IDE of choice (each editor/IDE has a different way of doing this, but most expose a way to attach to a running REPL by providing the host (usually localhost) and the port on which an nREPL server is running), or by invoking Leiningen directly at the command-line like this:
lein repl :connect <port>
You can specify the <port> when you configure the nREPL server as shown above. It also prints it out when it starts.
clj-debugger is a basic REPL debugger which provides features pretty similar to those available in pry-debug. You might consider it as an alternative to using the debuggers available in tools like CIDER & Cursive.
debugging is a huge problem in clojure as we are not aware of where the error occurred as well. define this macro :
(defmacro dbg[x] `(let x# ~x to understand where the eroor is thrown

Pressing arrow keys do not work correctly in Clojure console

I downloaded the Clojure jar. Its version is 1.6.0.
When I run Clojure in console I press arrow keys but they don't move the cursor but produce these characters "[[D^[[C.
I start Clojure using this command:
java -cp clojure-1.6.0.jar clojure.main
using Java 1.7.0_55 64 bit on Ubuntu 14.04 LTS 64 bit.
How can I get back normal arrow keys behaviour ?
The repl bundled with Clojure is pretty terrible. But that's okay, because you want to install Leiningen anyway, and its repl is much better, including the various readline stuff you're used to.
But in general, if there's some app that does a terrible job of being a repl, you can always use rlwrap to wrap the app in readline.
You are following hopelessly outdated instructions/tutorials. The generally accepted way to interact with all things clojure is through Leiningen. Then start Clojure by running:
lein repl
You can create a new web project by running:
lein new compojure my-project-name
or a new general project by running:
lein new my-project-name

Does Leiningen require a JDK/JRE?

I've tried to install Leiningen according to the official installation instructions. When running lein repl I get the following error message:
/usr/local/bin/lein: line 315: java: command not found
This leads me to believe that Leiningen requires a JDK/JRE to actually run but there is no mention of it in the docs. So, do I first need to install a JDK/JRE?
Yes, see installation instruction https://github.com/technomancy/leiningen#installation
Yes, you need to install JDK first.
Instruction for Windows installation is here
Leinengen comes packaged as a JAR file with a small bash script wrapping it, allowing for easy command line usage. This means that, like any other clojure or java program, it require the JVM to be run.
If you take a look at ~/.lein/self-installs/ you will see the JAR file(s) leiningen utilizes to run it's tasks.
One thing worthy of noting as well is that Leiningen starts its own JVM process before creating a new JVM process for your clojure program. They are not run in the same JVM container (to enforce isolation). Also, this initial Leiningen JVM process will not close until your clojure program has finished running as well (unless you utilize the trampoline).
As always, it's worth reading through the Leiningen docs at some point to better learn about what leiningen is truly doing. Hopefully that helps... happy coding!

Can't open clojure the project in Intellij IDEA with La Clojure

I was going through this tutorial
http://wiki.jetbrains.net/intellij/Getting_started_with_La_Clojure and I got stuck here
http://wiki.jetbrains.net/intellij/Getting_started_with_La_Clojure#Opening_project_in_IntelliJ_IDEA. I don't know way but 'open project' dialog does show the file 'project.clj'. So I'm not able open the clojure project. (And also I don't know how to create new one)
Is this bug of IDEA/La clojure or I did something wrong?
To open/import clj projects, you need to have the Leiningen plugin installed.
Unfortunately, the latest official release of the lein plugin for intellij doesn't work well with Intellij13 (crashed my idea on load every time until removed manually).
I'm guessing that because of Cursive there wasn't a newer release even though the latest version of the plugin on github does work.
I followed the instructions on the lein plugin's git page to create a plugin bundle from the latest version: https://github.com/derkork/intellij-leiningen-plugin
Assuming you're using Intellij13, creating the bundle yourself and then installing it from disk will enable you to open clj project files.

How to change Clojure or Lein's Clojure default version?

I'm not sure why but when I enter the REPL through $ clojure or $ lein repl, >(clojure-version) says '1.2.1'. I want it to say '1.5'.
Version 1.5 works fine in my projects managed by lein. I just want to tell lein to always use 1.5 by default, instead of 1.2.
Currently this isn't supported outside a project, but it's being worked on: https://github.com/technomancy/leiningen/issues/966
A workaround for now is just to specify it in your project.clj
Further recommendation: upgrade to Leiningen 2.0.