DEV Community

Ian Pedro
Ian Pedro

Posted on • Updated on

Starting with Clojure on Windows

Clojure has been one of the pretty cool things that I've been studying lately. The whole idea of a programming language with a 100% funcional paradigm, seemed to me very strange and challenging. Things got very weird when we get to the syntax, but that is discussion for another post!

So, let's cut to the chase: how to prepare your environment using Clojure (specifically leiningen) + VSCode + Windows.

Starting out with the dependencies! Well, check if you have all of the shenanigans below:

  • Windows (makes no sense reading this if you don't use Windows duh)
  • VSCode
  • Java 8 or 11 (LTS versions). Also need the JAVA_HOME environment set
  • Chocolatey (so we get leiningen without putting our hair on fire)

If you don't have chocolatey installed, then:

  • Run PowerShell as administrator, and execute the following:
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
  • Type choco to see if everything went well.

Now, to leiningen! But what is this awesome german guy can do for us? Well, it's porpose is to automate clojure projects. It can: create new projects, fetch dependencies, run a REPL, compile java sources and much more!

Since you already have chocolatey, with your powershell open, execute:

choco install lein

If everything went well, you now just need to restart your powershell, and create your project! Go to the the folder you want to keep the project and type in the command line:

lein new app hello-world

This will generate a project called "hello-word" with the app template.

Now, we need to open the project with VSCode and install the last need stuff.

With the project opened, you will see:

alt text

To install the extensions, so we can have more funcionatily inside VS, execute shift + ctrl + x, search for clojure and install:

alt text

Now, execute

lein repl

in the terminal, so the REPL is started.

alt text

With that out of the way we just need to connect the running nREPL with VS. Execute shift + ctrl + p, and search for repl, and select:

alt text

Press enter twice and voila, your environment is all set and good to go!

alt text

This is very basic, but is enough to get you started. In the next posts I want to show the very weird syntax, and make a approach on collections! Stay tuned.

Oldest comments (0)