Getting Started With Clojure and Visual Studio Code

  • Programmers that are writing Clojure for the first time professionally.

Dependencies

You will need Java, Clojure, Leiningen, and Visual Studio Code installed.

brew install adoptopenjdk clojure leiningen
brew cask install visual-studio-code

Calva

The only Visual Studio Code extension you will need to be productive with Clojure codebases is Calva. Make sure to have it installed.

Let’s tinker

In this next part, we’re going to:

  • Connect to the REPL using Visual Studio Code and Calva.
  • Evaluate Clojure expressions directly in your editor.
  • Evaluate and run tests directly in your editor.

Create a new Clojure project

Inside the directory you want to create your Clojure project, run

lein new clojure-sandbox

Jacking-In

A large part of building software with Clojure is the REPL. Programmers are familiar with the concept of a REPL from other programming languages (e.g. irb for Ruby, python3 for Python).

  1. Bring up Visual Studio Code’s command palette.
  2. Type in Jack-In and select the option Calva: Start a Project REPL and Connect (aka Jack-In)
  3. Select the Leiningen project type

Evaluating Clojure Forms

A quick screencast to help with visualising evaluating forms in Clojure.
(let [name "Muyiwa"]
(str "Hello " name))

Running Clojure Tests

To run Clojure tests in Visual Studio Code, open a test file (e.g. test/clojure_sandbox/core_test.clj and start typing calva test into the Visual Studio Code command palette.

  • Run Current Test
  • Run Failing Tests again
  • Run Tests for Current Namespace

Conclusion

If this is the beginning of your journey with Clojure and REPL driven development, I recommend the following next steps:

I love computers, design, and people. Lead Software Engineer at eporta.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store