Clojure
- Pronunciation
- KLOH-zher
In short
Clojure is a modern, dynamic dialect of Lisp that runs on the JVM, emphasizing immutable data, functional programming and interactive, REPL-driven development.
What is Clojure?
Clojure is a general-purpose programming language created by Rich Hickey and first released in 2007. It is a dialect of Lisp, one of the oldest families of programming languages, and it runs on the Java Virtual Machine, so Clojure code can call any Java library. ClojureScript is a sister implementation that compiles to JavaScript for browsers and Node.js.
Like all Lisps, Clojure writes code as nested lists in parentheses with the function first: (+ 1 2) instead of 1 + 2. Because code is written in the language's own data structures, a property called homoiconicity, macros can transform code before it runs and let developers extend the language itself. Clojure is dynamically typed and functional, and its core collections (lists, vectors, maps and sets) are immutable and persistent, meaning updates return new versions that efficiently share memory with the old ones. For state that must change, it provides controlled tools such as atoms, which update a value safely across threads.
Clojure is used for backend services, data processing and financial systems, and ClojureScript is used for web front ends. Developers typically work in a REPL connected to their running program, evaluating and redefining one function at a time, which feels more like a conversation with the application than an edit-compile-run cycle.
Clojure is often compared with other Lisps and with other JVM languages. Compared with older Lisps such as Common Lisp and Scheme, it adds literal syntax for vectors and maps, immutable data by default and tight integration with its host platform. Compared with Scala and Kotlin, which also run on the JVM, Clojure is dynamically typed and far more minimal in syntax, trading compile-time type checks for flexibility and interactive development.
Key takeaways
- Clojure is a Lisp dialect that runs on the JVM and can use Java libraries.
- Its core data structures are immutable and persistent.
- Code is written as data, so macros can extend the language.
- REPL-driven development lets you change a running program interactively.
- ClojureScript brings the same language to JavaScript environments.
Example
;; Maps are immutable: assoc returns a new map
(def user {:name "Ada" :langs ["clojure" "java"]})
(def updated (assoc user :role "admin"))
(println (:role user)) ;; nil (original unchanged)
(println (:role updated)) ;; admin
;; The ->> macro threads a value through a series of functions
(->> [1 2 3 4 5 6]
(filter even?)
(map #(* % %))
(reduce +)
(println)) ;; 56Readers ask
Why does Clojure have so many parentheses?
Clojure, like all Lisps, writes code as nested lists with the function name first inside each pair of parentheses. The uniform structure keeps the syntax very small and lets macros treat code as data, and editors balance the parentheses automatically.
Is Clojure a functional language?
Yes. Clojure encourages pure functions and immutable data and treats functions as values, but it is pragmatic: it allows side effects and offers managed ways to change state, such as atoms.
What is the difference between Clojure and ClojureScript?
They are the same language targeting different platforms. Clojure runs on the JVM and uses Java libraries, while ClojureScript compiles to JavaScript and runs in browsers or Node.js.
See also
- Functional ProgrammingProgramming Fundamentals, p. 22Functional programming is a style of building software from pure functions that avoid changing shared data, making code more predictable and easier to test.
- ImmutabilityProgramming Fundamentals, p. 27Immutability means a value cannot be changed after it is created, so every update produces a new value instead of modifying the original in place.
- JavaProgramming Languages, p. 15Java is a statically typed, object-oriented programming language that compiles to bytecode for the Java Virtual Machine, so programs run on many platforms.
- ScalaProgramming Languages, p. 30Scala is a statically typed JVM language that combines object-oriented and functional programming and is widely used for data engineering and backend systems.
- Lambda FunctionProgramming Fundamentals, p. 33A lambda function is a small function written inline without a name, usually passed straight to another function such as a sorting or filtering helper.
- ConcurrencyProgramming Fundamentals, p. 12Concurrency is a program's ability to make progress on several tasks in overlapping time periods, such as serving many users at once rather than one at a time.
- JVMProgramming Languages, p. 17The JVM runs Java bytecode, so the same compiled program works on any operating system; Kotlin, Scala and Clojure compile to that bytecode too.
Spotted a mistake or something missing on this page?Suggest an edit