Getting Started with Clojure on Mac OS

Written by swlkr | Published 2017/09/14
Tech Story Tags: clojure | mac | cursive | programming | software-development

TLDRvia the TL;DR App

Hey, psssst, I made an updated version of this post here

There are a few things you need to run clojure on your Mac, the first thing is called leiningen and it works like npm for nodejs or bundler for ruby, or the dotnet cli for c#, it’s a project runner and a dependency manager (sort of).

Here’s how you install it:

brew install leiningen

That’s it! That was painless. Unless it wasn’t in which case you don’t have homebrew installed, and you should do this first:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

There we go, run that first thing again, now it was painless. Next step, start a new clojure project:

lein new my-project

Hey, this lein thing is pretty simple and pretty easy. Next step is to actually run the project. Open up your favorite text editor, scratch that, go ahead and install intellij community edition. I’ll wait. Now that it’s installed, install the cursive plugin. Now you’re ready to edit some clojure with zero configuration!

cd my-projectidea .

Open up src/my_project/core.clj and add a new function

(defn hello [name](str "hello " name))

Now click the project name in the tree view on the left and press ctrl + shift + R. A REPL should show up on the right. Move the cursor to the function you just made, type cmd + shift + P (or ctrl + shift + T, depending on your keymap). The function will be sent to the repl. Now below your function type

(hello "world")

And hit cmd + shift + P (or ctrl + shift + T) again.

Sending “forms” to the REPL (the stuff in parens) from your editor is a great thing, you don’t have to type out things directly in the REPL, where I think a lot of people think that’s what a REPL is. You can build up a lot of state in the REPL without closing it for weeks and without directly typing in it at all. I also made another small screencast showing going from lein in the terminal to cursive and sending forms to the REPL. It’s pretty raw, and it’s only a minute, but hopefully it will convince you to give clojure a shot!


Written by swlkr | 🏔 Takes hikes ⌨️ Makes sites
Published by HackerNoon on 2017/09/14