Last Updated: November 21, 2025
Clojure
Modern Lisp on the JVM
Basic Syntax
; Variables
(def name "John")
(def age 30)
; Functions
(defn greet [name]
(str "Hello, " name))
; Collections
(def numbers [1 2 3 4 5])
(def person {:name "John" :age 30})
(def unique-nums #{1 2 3})
; Map and filter
(map inc numbers) ; [2 3 4 5 6]
(filter even? numbers) ; (2 4)
; Threading macros
(->> numbers
(map inc)
(filter even?)
(reduce +))
Data Structures
| Item | Description |
|---|---|
[1 2 3]
|
Vector (indexed) |
(1 2 3)
|
List (sequential) |
{:a 1 :b 2}
|
Hash map |
#{1 2 3}
|
Set (unique values) |
(first coll)
|
First element |
(rest coll)
|
All but first |
Concurrency
; Atoms for synchronous state
(def counter (atom 0))
(swap! counter inc)
@counter ; Deref to get value
; Agents for asynchronous state
(def logger (agent []))
(send logger conj "Log entry")
; Refs for coordinated state (STM)
(def account1 (ref 100))
(def account2 (ref 200))
(dosync
(alter account1 - 50)
(alter account2 + 50))
Best Practices
- Prefer immutable data structures
- Use threading macros for readability
- Leverage REPL-driven development
- Use atoms for simple state management
💡 Pro Tips
Quick Reference
Clojure emphasizes immutability and simplicity