Getting Started with Clojure is now easier than ever - On a Mac

As of Dec 8, 2017 a brew recipe has been added to install Clojure with brew install clojure and it gives you commands clj and clojure.

To try it out, I created a file, test.clj with the following:

#!/usr/bin/env clojure

(println "Hello World")

(println (+ 1 2 3 4 5))

(println (clojure.string/upper-case "hello world"))

After you make it executable with:

chmod u+x test.clj

You can execute it:

▶ ./test.clj
Hello World

A popular way to play with Clojure is to use a repl. You can start a repl, by using either clj or clojure without a file name

Clojure 1.9.0
user=> (+ 1 2 3 4)
user=> (apply str [1 2 3 4])
user=> (map #(* 2 %) [1 2 3 4])
(2 4 6 8)

I was curious about commands clojure and clj and found an explaination of how it works.

You can have a deps.edn file to include dependencies. At first I was confused on :mvn/ prefix, and thought how to include a library from clojars? So I looked farther and found that :mvn includes this group of locations (which includes clojars), as shown here.

 {"central" {:url ""}
  "clojars" {:url ""}}}

to test this out, I created a directory and put a file deps.edn file with the following:

 {anagrams {:mvn/version "4" }}}

Anagrams is a fun little library I found browsing clojars. It takes a list of words separated with \n and finds words that are anagrams of a word you give it. My example is a little contrived, but see it working:

Start the repl in that same directory, if needed it will download and install dependencies:

Clojure 1.9.0
user=> (require '[anagrams.core :as a])

user=> (a/set-word-list! "cat\ntac\natc\ndog\ngod\ntaco") "done"

user=> (a/anagrams-of "cat") #{"tac" "atc" "cat"}

user=> (a/anagrams-of "dog") #{"dog" "god"}

Cool, that's fun :)

A new way to try out Clojure.. (on a mac at least). Pretty easy!