Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 36 ยท Getting Started

Introduction to Clojure

Meet Clojure, a modern Lisp for the JVM and JavaScript built around immutable data, simple functions and a live REPL. Learn what makes it different and where it is used.

Clojure is a modern, dynamically typed Lisp. It was created by Rich Hickey and first released in 2007. Instead of inventing a new runtime, it runs on platforms that already exist: the Java Virtual Machine (JVM), JavaScript engines (through ClojureScript) and the .NET CLR. That means you get mature libraries, good performance and easy deployment, but you write code in a very small, very regular language.

Three ideas shape everything you will see in this course. First, data is immutable by default: "changing" a collection gives you a new collection and leaves the old one untouched. Second, code is data: a Clojure program is written as the same lists and vectors you use for your own data, which makes the language easy to extend. Third, you work interactively: instead of the edit, compile, run cycle, you keep a program running in a REPL and send new code into it.

Clojure does not run on this site, so Clojure code blocks in this course are read-only. Where a concept can be demonstrated in the browser, we add a small, clearly labelled JavaScript stand-in that you can edit and run. The stand-ins show the idea, not real Clojure behaviour. To run real Clojure, install it as shown in Installing Clojure and Using the REPL.

What makes Clojure different

Clojure in one picture

Immutable data Values never change. You make new ones.
Code is data Programs are lists, vectors and maps.
Live REPL Grow a running program, one form at a time.
1 / 2

A Lisp without the parenthesis fear

Lisp is famous for parentheses. In Clojure every operation is written as a list whose first element is the thing to do:

CLOJURE
(+ 1 2 3)           ; add three numbers
(str "Hello, " "Clojure")
(println "hi")

At first the placement feels backwards compared with 1 + 2 + 3, but there is a payoff: there are no operator precedence rules to memorize, and + accepts any number of arguments. Clojure also adds square brackets [] for vectors, curly braces {} for maps and #{} for sets, so the code is easier to scan than classic Lisp.

Functional first, pragmatic always

Clojure encourages programming with pure functions: functions whose result depends only on their arguments. They are easy to test, easy to reason about and safe to run in parallel. But Clojure is not a purist language. It lets you call Java methods, mutate state in a controlled way (with atoms, refs and agents, covered in the concurrency chapter) and do input and output wherever you need it.

Compared with other languages you may know:

Idea Clojure
Types Dynamic. Values have types, variables do not.
Collections Immutable and persistent (they share structure).
Objects Mostly plain maps plus functions; protocols and records when needed.
Loops Mostly map, filter, reduce; explicit loop/recur when needed.
Concurrency Built-in tools for shared state: atoms, refs, agents, core.async (a library).

Where Clojure is used

Clojure shows up in data-heavy backends, finance and e-commerce systems, analytics pipelines, developer tools and web applications. ClojureScript powers single-page front ends, often with React wrappers. Babashka, a fast-starting Clojure interpreter, is popular for shell scripting. It is a small community compared with Java or Python, but it is known for being experienced, productive and welcoming.

A taste of what is coming

The following read-only snippet counts the words in a sentence. Do not worry about every detail yet; the rest of the course explains each piece.

CLOJURE
(def sentence "the cat and the hat and the bat")

(->> (clojure.string/split sentence #" ")
     frequencies
     (sort-by val >)
     first)
;; => ["the" 3]

Read it as a pipeline: split the text into words, count each word, sort by count (largest first), take the top entry. No variables are updated and no loops are written.

The same idea can be tried in the browser with a JavaScript stand-in. It follows the same steps, but JavaScript needs a little more ceremony.

JS Stand-in: word frequency pipeline

Press Run (or Ctrl + Enter) to see the console output here.

No output.

In Clojure, frequencies replaces the whole counting loop. Part of learning Clojure is discovering that the standard library already contains many such building blocks.

Immutability at a glance

Here is another stand-in: a tiny "update" that returns a new object instead of changing the old one. Real Clojure collections do this efficiently by sharing structure (explained in Immutability and Persistent Data).

JS Stand-in: values that do not change

Press Run (or Ctrl + Enter) to see the console output here.

No output.

In Clojure the equivalent is (assoc before :visits 2), which returns a new map and leaves before exactly as it was.

How this course is organized

You will start with installing Clojure and reading its syntax, then learn numbers, strings, truthiness and local names. Next come the four core collections, then functions and higher-order functions. Later chapters cover lazy sequences, state and concurrency, macros and protocols, tooling and Java interop, and finally projects and practice problems.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which platform does Clojure NOT natively target?

    Clojure targets the JVM, JavaScript engines and the CLR. Python is not one of its host platforms.
  2. 2. What does 'data is immutable by default' mean?

    Updating an immutable value produces a new value; the original stays the same.
  3. 3. In (+ 1 2 3) which element is the operation?

    In Clojure the first element of a list form is the function (or operator) to call; the rest are arguments.
  4. 4. Why do the JavaScript examples in this course say 'stand-in'?

    They are labelled illustrations that run in the browser; real Clojure behaviour may differ.

Summary

  • Clojure is a modern Lisp that runs on the JVM, in JavaScript (ClojureScript) and on .NET.
  • Immutable data, code as data and an interactive REPL are its three signature ideas.
  • Every operation is a list with the function first: (+ 1 2 3).
  • It is functional by default but pragmatic: Java interop and controlled mutable state are available.
  • On this site Clojure blocks are read-only; JavaScript stand-ins are labelled.

Next: Installing Clojure and Using the REPL