# Clojure — Functional Lisp for the JVM > Clojure is a dynamic functional programming language that runs on the JVM, emphasizing immutability, concurrency, and interactive development through its REPL-driven workflow. ## Install Save as a script file and run: # Clojure — Functional Lisp for the JVM ## Quick Use ```bash # Install via Homebrew (macOS/Linux) brew install clojure/tools/clojure # Start a REPL clj # Create a project with deps.edn mkdir myapp && cd myapp echo '{:deps {org.clojure/clojure {:mvn/version "1.12.0"}}}' > deps.edn clj -M -e '(println "Hello, Clojure!")' ``` ## Introduction Clojure is a Lisp dialect hosted on the Java Virtual Machine, designed by Rich Hickey. It treats code as data, defaults to immutable data structures, and provides built-in primitives for safe concurrent programming, making it a practical choice for data-intensive and server-side applications. ## What Clojure Does - Provides persistent immutable data structures (lists, vectors, maps, sets) with structural sharing - Runs on the JVM with seamless access to the entire Java ecosystem - Offers software transactional memory (STM), atoms, and agents for safe concurrency - Supports interactive development via a networked REPL (nREPL) - Compiles to JavaScript via ClojureScript for frontend and full-stack applications ## Architecture Overview Clojure source is read by the reader into data structures, then compiled directly to JVM bytecode — there is no interpreter step. Persistent data structures use hash array mapped tries for efficient structural sharing. The STM system coordinates state changes across refs using multiversion concurrency control. The deps.edn tool resolves Maven and Git dependencies, while Leiningen remains a popular alternative build tool. ## Self-Hosting & Configuration - Install the Clojure CLI tools or use Leiningen (`lein`) as project manager - Declare dependencies in `deps.edn` (CLI) or `project.clj` (Leiningen) - Connect an editor (Emacs+CIDER, VS Code+Calva, IntelliJ+Cursive) to the nREPL for interactive development - Use GraalVM native-image to compile Clojure programs to standalone binaries - Deploy as standard JAR files or uberjars on any JVM-compatible platform ## Key Features - Homoiconic syntax enables powerful macros that extend the language at compile time - Spec library provides runtime data validation and generative testing - Transducers offer composable data transformations without intermediate collections - core.async brings CSP-style channels and go blocks for asynchronous programming - Full Java interop with zero-overhead method calls and class instantiation ## Comparison with Similar Tools - **Kotlin** — Statically typed JVM language; Clojure is dynamic with a focus on functional paradigms - **Scala** — Combines OO and FP on the JVM; Clojure takes a purer functional approach with simpler syntax - **Elixir** — Functional with actor concurrency on BEAM; Clojure uses STM on the JVM - **Haskell** — Pure FP with advanced type system; Clojure is dynamically typed and pragmatic - **Common Lisp** — Older Lisp with mutable defaults; Clojure defaults to immutability on a modern runtime ## FAQ **Q: Is Clojure fast enough for production?** A: Yes. Clojure compiles to JVM bytecode and benefits from HotSpot JIT optimization, achieving performance comparable to Java. **Q: Can I use Java libraries from Clojure?** A: Directly. Java classes, methods, and interfaces are first-class citizens in Clojure with no wrapper code needed. **Q: What is ClojureScript?** A: ClojureScript compiles Clojure to JavaScript, enabling shared logic between backend and frontend with tools like shadow-cljs. **Q: How does Clojure handle errors?** A: Clojure uses JVM exceptions. Libraries like ex-info attach data maps to exceptions for structured error handling. ## Sources - https://github.com/clojure/clojure - https://clojure.org --- Source: https://tokrepo.com/en/workflows/asset-43a7d83c Author: Script Depot