Clojure Cheat Sheet
Clojure syntax, immutable data structures, persistent collections, and functional idioms for modern concurrent JVM programming.
2 PagesAdvancedMar 28, 2026
Basic Syntax
Bindings, control flow, and printing.
clojure
(def age 30)(def name "Ada")(def pi 3.14159)(if (>= age 18) (println name "is an adult") (println name "is a minor"))(doseq [i (range 5)] (println "Count:" i))
Collections
Persistent vectors, maps, and sequence functions.
clojure
(def nums [5 3 1 4 2]) ; vector (immutable)(def evens (filter even? nums)) ; (4 2)(def squared (map #(* % %) nums)) ; (25 9 1 16 4)(def total (reduce + nums)) ; 15(def sorted (sort nums)) ; (1 2 3 4 5)(def person {:name "Ada" :age 30}) ; map literal(:name person) ; "Ada", keyword-as-function lookup(assoc person :age 31) ; returns new map, original unchanged
Concurrency Primitives
Managed references for shared state.
clojure
(def counter (atom 0)) ; mutable reference, synchronous updates(swap! counter inc) ; atomically increments@counter ; deref, reads current value => 1(def account (ref 100)) ; coordinated (STM) reference(dosync (alter account - 30)) ; transactional update(future (Thread/sleep 1000) (println "done")) ; runs on another thread
Core Forms
Common Clojure special forms and macros.
- def- binds a symbol to a value in the current namespace
- defn- defines a named function
- let- creates local bindings scoped to a body of code
- fn / #()- anonymous function literal (long and shorthand forms)
- atom- uncoordinated, synchronous mutable reference type
- ->/->>- threading macros that thread a value through function calls
- keyword (:key)- self-evaluating symbol commonly used as a map key or accessor
Pro Tip
Use the `->` and `->>` threading macros to flatten deeply nested function calls into a readable top-to-bottom pipeline, instead of reading inside-out.
Was this cheat sheet helpful?
Explore Topics
#Clojure#ClojureCheatSheet#Programming#Advanced#BasicSyntax#Collections#ConcurrencyPrimitives#CoreForms#DataStructures#Concurrency#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech
Professional Web Designing Services
- Responsive Websites
- E-commerce Solutions
- SEO Friendly Design
- Fast & Secure
- Support & Maintenance