New Clojure REPL Experience With Clj Tools and Rebel Readline

A REPL is the foundation of the Clojure coding experience. The REPL provides a runtime environment where you can instantly get the results of evaluating your code. You can write code in a REPL too, although typically code is written editor and sent to a REPL to be evaluated. When you start coding, the first step is to run the REPL and keep it running until you are finished.

A REPL is the same environment used for running your Clojure applications too.

Lets look at the newest and fastest approach to running a Clojure REPL, the Clojure CLI Tools and rebel-readline.

Clojure CLI Tools

The Clojure CLI tools included in Clojure 1.9 provides a REPL that starts instantly, so its a great way to introduce developers to Clojure.

Follow the Clojure CLI Tools Getting Started Guide to install on Linux or Mac (Windows is not supported at time of publication). Once installed, use the clojure or clj command in a terminal to start your REPL.

Clojure CLI Tools REPL

Using Libraries with your project

Library dependencies are defined in a file called deps.edn which uses the Extensible Data Notation (EDN), the data notation that Clojure is designed on top of.

rebel-readline - enhancing the repl experience

Rebel-readline enhances the REPL experience by providing multi-line editing with auto-indenting, language completions, syntax highlighting and function argument hints as you code.

With the CLI tools installed, run the following in a terminal:

clojure -Sdeps "{:deps {com.bhauman/rebel-readline {:mvn/version \"0.1.4\"}}}" -m rebel-readline.main

That should start a Clojure REPL that takes its input from the Rebel readline editor.

Use the clojure command. The clj command wraps the process with another readline program (rlwrap), so does not work with rebel-readline.

Alternatively, specify an alias in your $HOME/.clojure/deps.edn

:aliases {:rebel {:extra-deps {com.bhauman/rebel-readline {:mvn/version "0.1.4"}}
:main-opts ["-m" "rebel-readline.main"]}}

And then run with a simpler command:

$ clojure -A:rebel

When you run clojure for the first time with rebel-readline it will take a few seconds as it will download the library dependencies.

What is a readline
allows multi-line editing and general navigation around forms using the keyboard arrow keys

Thank you.

This work is licensed under a Creative Commons Attribution 4.0 ShareAlike License, including custom images & stylesheets. Permissions beyond the scope of this license may be available at @jr0cket
Creative Commons License