TLDR: Polish notation and symbols

With Clojure you can write code that is clear. Mabye even as clear as this photo. Photo by Mohan Murugesan on Unsplash

What is Clojure?

Clojure is a dynamic, general-purpose programming language, combining the approachability and interactive development of a scripting language with an efficient and robust infrastructure for multithreaded programming.

The main things to note about Clojure are as follows:

Clojure is a Lisp dialect.

Clojure runs on the JVM.

Clojure supports functional programming.

Installing Clojure

On OSX you can simply run the following command if homebrew is installed.

brew install leiningen

On windows you can run the following command if chocolatey is installed. I have not personally tried this yet.

choco install lein

Just let leiningen take care of everything.

Leiningen: a tool for automating Clojure projects.

Make sure Java is installed as well. I won’t go over this in detail.

Editor Setup

I would recommend using Visual Studio Code with the Calva extension for a good experience.

Opening the REPL

Go to your terminal and enter in the following command. (I am testing this on MacOS.)

lein repl

The output should be similar to the following. (The version number and a few other details might be different.)

Retrieving nrepl/nrepl/0.6.0/nrepl-0.6.0.pom from clojars

Retrieving clojure-complete/clojure-complete/0.2.5/clojure-complete-0.2.5.pom from clojars

Retrieving nrepl/nrepl/0.6.0/nrepl-0.6.0.jar from clojars

Retrieving clojure-complete/clojure-complete/0.2.5/clojure-complete-0.2.5.jar from clojars

nREPL server started on port 63585 on host 127.0.0.1 - nrepl://127.0.0.1:63585

REPL-y 0.4.3, nREPL 0.6.0

Clojure 1.10.0

OpenJDK 64-Bit Server VM 12.0.1+12

Docs: (doc function-name-here)

(find-doc "part-of-name-here")

Source: (source function-name-here)

Javadoc: (javadoc java-object-or-class-here)

Exit: Control+D or (exit) or (quit)

Results: Stored in vars *1, *2, *3, an exception in *e user=>

You now have access to the Clojure REPL. Hooray!

Polish notation

Let us look at a simple problem. Show 1 + 1 in code. In a language like JavaScript or Python you might show it like this.

1 + 1

This is called infix notation and involves placing operators between operands.

Let us look at how we can do the same thing in Clojure.

(+ 1 1)

This is called polish notation and involves placing operators before operands.

Here are a few more examples of polish notation in action.

(+ 10 10 10) (- 10 5) (* 10 10 10) (/ 10 2)

Symbols

Symbols work the way symbols work in algebra. Let us say that I want the symbol x to represent 5, I would show it like this.

(def x 5)

For now I would suggest getting comfortable with symbols and polish notation. In the next article we will look at defining functions and what you can do with them.

Links and further reading

Thank you!

I hope that you managed to get started with Clojure today. If you enjoyed the article or have any feedback, do let me know in the comment section. Thank you very much.