Clojure
Overview
Clojure is a dynamic, functional Lisp that compiles to JVM bytecode (with ClojureScript targeting JavaScript), built around immutable persistent data structures and a REPL-driven workflow. It emphasizes pure functions, explicit state, and easy Java interop. Read this when writing Clojure, setting up the CLI/deps.edn, using the REPL, or reasoning about its concurrency primitives.
Official sources
Install / setup
# macOS (Homebrew); Java 11+ required
brew install clojure/tools/clojure
clj # start a REPL
Command per https://clojure.org/guides/install_clojure (Linux uses the linux-install.sh script from the same page).
Core concepts
- Immutable persistent data structures — lists, vectors, maps, sets are values; "updates" return new structures via structural sharing.
- REPL-driven development — evaluate forms interactively against a running program; the core of the Clojure workflow.
- Homoiconicity & macros — code is data (s-expressions);
defmacro transforms forms at compile time.
- deps.edn & the CLI —
clj/clojure resolve dependencies from deps.edn; tools.deps is the official build/run mechanism.
- Sequences & laziness — the
seq abstraction plus lazy sequences over collections; map/filter/reduce are universal.
- Concurrency primitives —
atom (uncoordinated sync state), ref+dosync (STM), agent (async), volatile.
- Java interop — call any Java via
(.method obj), (Class/staticMethod), and (new Class) / Class..
- Transducers — composable, source-independent transformations decoupled from input/output collections.
Best practices
Common pitfalls
- Holding the head of a large lazy seq → memory blowup; consume eagerly with
doall/reduce or avoid retaining the binding.
- Expecting side effects inside lazy
map to run → use doseq/run! for effects, not lazy sequences.
- Confusing
= (value equality) with identical? (reference) on immutable values → use =.
Examples
(defn word-freq [text]
(->> (re-seq #"\w+" text)
(map clojure.string/lower-case)
(frequencies)
(sort-by val >)))
(word-freq "the cat the dog the cat")
;; => ([\"the\" 3] [\"cat\" 2] [\"dog\" 1])
Further reading
Related skills
- ../haskell — another functional language emphasizing immutability and pure functions
- ../erlang — shares a focus on concurrency and the actor/process model
- ../lua — fellow dynamically typed embeddable language
1---2name: clojure3description: Clojure is a dynamic, functional Lisp dialect on the JVM with immutable persistent data structures and strong concurrency support; consult when writing Clojure, using the Clojure CLI/deps.edn or Leiningen, working with the REPL, transducers, atoms/refs/agents, or interop with Java and ClojureScript.4domain: language5category: language6tags: [clojure, lisp, jvm, functional, repl, deps-edn, clojurescript]7official_sources:8 - https://clojure.org/9 - https://github.com/clojure/clojure10 - https://clojure.org/guides/install_clojure11verified: 2026-06-1712metadata:13 source: https://skillmd.com/skills/gabriel7silva/clojure14---1516# Clojure1718## Overview19Clojure is a dynamic, functional Lisp that compiles to JVM bytecode (with ClojureScript targeting JavaScript), built around immutable persistent data structures and a REPL-driven workflow. It emphasizes pure functions, explicit state, and easy Java interop. Read this when writing Clojure, setting up the CLI/deps.edn, using the REPL, or reasoning about its concurrency primitives.2021## Official sources22- Docs: https://clojure.org/23- Repo: https://github.com/clojure/clojure24- Install: https://clojure.org/guides/install_clojure2526## Install / setup27```bash28# macOS (Homebrew); Java 11+ required29brew install clojure/tools/clojure30clj # start a REPL31```32Command per https://clojure.org/guides/install_clojure (Linux uses the `linux-install.sh` script from the same page).3334## Core concepts35- **Immutable persistent data structures** — lists, vectors, maps, sets are values; "updates" return new structures via structural sharing.36- **REPL-driven development** — evaluate forms interactively against a running program; the core of the Clojure workflow.37- **Homoiconicity & macros** — code is data (s-expressions); `defmacro` transforms forms at compile time.38- **deps.edn & the CLI** — `clj`/`clojure` resolve dependencies from `deps.edn`; tools.deps is the official build/run mechanism.39- **Sequences & laziness** — the `seq` abstraction plus lazy sequences over collections; `map`/`filter`/`reduce` are universal.40- **Concurrency primitives** — `atom` (uncoordinated sync state), `ref`+`dosync` (STM), `agent` (async), `volatile`.41- **Java interop** — call any Java via `(.method obj)`, `(Class/staticMethod)`, and `(new Class)` / `Class.`.42- **Transducers** — composable, source-independent transformations decoupled from input/output collections.4344## Best practices45- Drive development from the REPL; reload changed namespaces rather than restarting (https://clojure.org/guides/repl/introduction).46- Prefer pure functions on immutable data; isolate state in `atom`/`ref` and mutate explicitly (https://clojure.org/reference/atoms).47- Use `deps.edn` aliases for tasks (test, build, run) instead of ad-hoc scripts (https://clojure.org/guides/deps_and_cli).48- Add type/shape checks with `clojure.spec` at boundaries (https://clojure.org/guides/spec).4950## Common pitfalls51- Holding the head of a large lazy seq → memory blowup; consume eagerly with `doall`/`reduce` or avoid retaining the binding.52- Expecting side effects inside lazy `map` to run → use `doseq`/`run!` for effects, not lazy sequences.53- Confusing `=` (value equality) with `identical?` (reference) on immutable values → use `=`.5455## Examples56```clojure57(defn word-freq [text]58 (->> (re-seq #"\w+" text)59 (map clojure.string/lower-case)60 (frequencies)61 (sort-by val >)))6263(word-freq "the cat the dog the cat")64;; => ([\"the\" 3] [\"cat\" 2] [\"dog\" 1])65```6667## Further reading68- https://clojure.org/reference/documentation — official language reference index69- https://clojuredocs.org/ — community examples for core functions70- https://clojure.org/guides/deps_and_cli — deps.edn and CLI guide7172## Related skills73- ../haskell — another functional language emphasizing immutability and pure functions74- ../erlang — shares a focus on concurrency and the actor/process model75- ../lua — fellow dynamically typed embeddable language