Clojure is a modern Lisp dialect for the Java Virtual Machine (with versions for the CLR and JavaScript). More than merely an implementation of Lisp in Java, Clojure provides access to Java's classes and ecosystem.
Clojure is a Lisp dialect for the Java Virtual Machine (with versions for the CLR and JavaScript).
Clojure is a modern Lisp dialect with an emphasis on functional programming (lazy/impure), running on the JVM with transparent access to all Java libraries, an interactive REPL development environment, dynamic runtime polymorphism, Lisp-style macro meta-programming and concurrent programming capabilities supported by software transactional memory.
Key features:
- Lisp heritage - Clojure is a fully homoiconic language with support for macro-based metaprogramming. The full features of the language are available at compile time, and it is possible to manipulate "code as data". These mechanisms are frequently used to extend the language itself or create new domain-specific languages.
- Functional programming - Clojure is primarily a functional language. It features immutable data structures and lazy sequences. Like many other Lisps, it is eagerly evaluated (although lazy sequences, macros and closures can be introduced to obtain lazy behavior) and impure.
- Concurrent programming, supported by software transactional memory, and designed for multi-core environments.
- Dynamic - Clojure is a dynamic language. However it should be noted that it is still fully compiled, exploits primitive operations on the JVM where needed for performance and can also support (optional) static type hints.
- Hosted on the JVM, allowing for easy and transparent access to the wide ecosystem of Java libraries.
- Open source - Clojure is run as a collaborative open source project (hosted on GitHub) and there is a rapidly growing ecosystem of open source libraries for Clojure, in addition to all the open source tools already available for Java
- Portable - Clojure can run on any platform that supports the JVM, and Clojure versions are also available for the CLR (ClojureCLR) and JavaScript (ClojureScript)
- Software Transactional Memory (STM) providing Multiversion Concurrency Control (MVCC) - Clojure refs provide thread safety and concurrency benefits without requiring explicit locking by the Clojure programmer
Code Samples:
Hello world is simple:
(println "Hello World!")
The "infamous" Lisp parentheses are used to apply a function, which is always the first item in the list:
(+ 1 2 3 4)
=> 10
Functions can easily be defined and passed to higher order functions like map
:
(defn triple [x]
(+ x x x))
(map triple [1 2 3 4 5 10])
=> (3 6 9 12 15 30)
Infinite lazy sequences are fully supported:
(take 7 (iterate (partial str "a") "b"))
=> ("b" "ab" "aab" "aaab" "aaaab" "aaaaab" "aaaaaab")
You can even do powerful computations on infinite sequences, such as defining the complete Fibonacci series:
(def fibonaccis
(lazy-cat [0 1] (map + fibonaccis (rest fibonaccis))))
(take 10 fibonaccis)
=> (0 1 1 2 3 5 8 13 21 34)
Resources:
Web Sites
- Clojure Home Page
- Clojure Documentation
- ClojureDocs
- Clojars Community OpenSource Repository
- Clojure Github Repositories
- Clojure Google Group Archives
- Clojure Style Guide
- Clojure/conj
- References and Cheat Seets
- ClojureScript
- ClojureCLR
- Web Frameworks
Tools
- Leiningen and a number of plugins
- Sublime Text Support
- Cursive IntelliJ Plugin
- LaClojure Plugin
- Counterclockwise Eclipse Plugin
- Netbeans Enclosure Plugin
- Atom with Parinfer
- Emacs with clojure-mode and CIDER
- Light Table Editor
- Clojure Toolbox
Books
- O'Reilly
- Manning
- APress
- The Pragmatic Bookshelf
- PaktPub
- No Starch Press Clojure for the Brave and True
- Lean Pub
- Others
Articles
- InfoQ
- Planet Clojure
- Disclojure
- Clojure at Reddit
- Success Stories
- Who is using Clojure?
- Clojure at Scale by Walmart
- 60,000% Growth Using Clojure and AWS by Room Key
- Unlocking Data-Driven Systems by Consumer Reports
- Beanstalk + Clojure = Love (and 20x better performance)
- Clojure at a Newspaper
- Lessons Learned from Adopting Clojure
- Prismatic: Om sweet Om: (high-) functional frontend engineering with ClojureScript and React
- Sonian: Staying SAFE: A Foundation for Clojure Applications
Videos
- ClojureTV
- InfoQ
- RESTful Clojure
- Clojure and the Web
- What Sucks about Clojure...and why you'll love it anyway
- Clojure after the Honeymoon
- Down the Clojure Rabbit Hole
- An Introduction to Clojure and ClojureScript
- Relevance of ClojureScript
- Why Prismatic Goes Faster with Clojure
- Clojure core.async
- Concurrency in Clojure
- Clojure Solution to the Expression Problem
- Clojure: The Art of Abstraction
- Namespaces, Vars and Symbols (Oh, My!)
- Clojure in the Field
- Continuous Testing in Clojure
- Leiningen 2 - Humane build management for Clojure
- Macros: Why, When and How?
- Persistent Data Structures and Managed References by Rich Hickey
- Rich Hickey on Protocols and Clojure 1.3
- Rich Hickey on Clojure's Features and Implementation
- Clojure
- Are We There Yet?
- Persistent Data Structures and Managed References
- Stuart Halloway on Clojure and Functional Programming
- Channel 9
- Vimeo
Exercises
Trainings
- PluralSight
- Safari/O'Reilly