For similarly sounding names, see closure.
|Designed by||Rich Hickey|
|First appeared||2007; 13 years ago (2007)|
/ 6 June 2019; 18 months ago (2019-06-06)
/ 5 March 2020; 9 months ago (2020-03-05)
|License||Eclipse Public License|
This focus on programming with immutable values and explicit progression-of-time constructs is intended to facilitate developing more robust, especially concurrent, programs that are simple and fast.
Commercial support for Clojure is provided by Cognitect.
Clojure conferences are organized every year across the globe, the most famous of them being Clojure/conj.
History and development process
Rich Hickey is the creator of the Clojure language.
Before Clojure, he developed dotLisp, a similar project based on the .NET platform, and three earlier attempts to provide interoperability between Lisp and Java: a Java foreign language interface for Common Lisp (jfli), A Foreign Object Interface for Lisp (FOIL), and a Lisp-friendly interface to Java Servlets (Lisplets).
Hickey spent about 2½ years working on Clojure before releasing it publicly, much of that time working exclusively on Clojure with no outside funding.
At the end of this time, Hickey sent an email announcing the language to some friends in the Common Lisp community.
The development process is community-driven and is managed at the Clojure JIRA project page.
General development discussion occurs at the Clojure Google Group.
Anyone can submit issues and ideas at ask.clojure.org, but to contribute patches, one must sign the Clojure Contributor agreement.
JIRA issues are processed by a team of screeners and finally Rich Hickey approves the changes.
Clojure's name, according to Hickey, is a pun on the programming concept "closure" incorporating the letters C, L, and J for C#, Lisp, and Java respectively—three languages which had a major influence on Clojure's design.
Clojure's approach to state is characterized by the concept of identities, which are represented as a series of immutable states over time.
Since states are immutable values, any number of workers can operate on them in parallel, and concurrency becomes a question of managing changes from one state to another.
For this purpose, Clojure provides several mutable reference types, each having well-defined semantics for the transition between states.
|Version||Release date||Major features/improvements|
|October 16, 2007||Initial public release|
|1.0||May 4, 2009||First stable release|
|1.1||December 31, 2009||Futures|
|1.2||August 19, 2010||Protocols|
|1.3||September 23, 2011||Enhanced primitive support|
|1.4||April 15, 2012||Reader literals|
|1.5||March 1, 2013||Reducers|
|1.5.1||March 10, 2013||Fixing a memory leak|
|1.6||March 25, 2014||Java API, improved hashing algorithms|
|1.7||June 30, 2015||Transducers, reader conditionals|
|1.8||January 19, 2016||Additional string functions, direct linking, socket server|
|1.9||December 8, 2017||Integration with spec, command-line tools|
|1.10||December 17, 2018||Improved error reporting, Java compatibility|
|Current stable version: 1.10.1||June 6, 2019||Working around a Java performance regression and improving error reporting from clojure.main|
|Legend:Old versionOlder version, still maintainedLatest versionLatest preview versionFuture release|
Leiningen handles project package management and dependencies and is configured using Clojure syntax.
Like most other Lisps, Clojure's syntax is built on S-expressions that are first parsed into data structures by a reader before being compiled.
Clojure is a Lisp-1 and is not intended to be code-compatible with other dialects of Lisp, since it uses its own set of data structures incompatible with other Lisps.
This helps prevent unintended name capture, as binding to namespace-qualified names is forbidden.
It is possible to force a capturing macro expansion, but it must be done explicitly.
Clojure does not allow user-defined reader macros, but the reader supports a more constrained form of syntactic extension.
Clojure supports multimethods and for interface-like abstractions has a protocol based polymorphism and data type system using records, providing high-performance and dynamic polymorphism designed to avoid the expression problem.
Automatic tail call optimization is not supported as the JVM does not support it natively; it is possible to do so explicitly by using the recur keyword.
Clojure 1.7 introduced reader conditionals by allowing the embedding of Clojure and ClojureScript code in the same namespace.
Transducers were added as a method for composing transformations.
While traditionally these functions operate on sequences, transducers allow them to work on channels and let the user define their own models for transduction.
The primary platform of Clojure is Java, but other target implementations exist.
A survey of the Clojure community with 1,060 respondents conducted in 2013 found that 47% of respondents used both Clojure and ClojureScript when working with Clojure.
In 2014 this number had increased to 55%, in 2015, based on 2,445 respondents, to 66%.
Popular ClojureScript projects include implementations of the React library such as Reagent, re-frame, Rum, and Om.
Other implementations of Clojure on different platforms include:
- CljPerl, Clojure atop Perl
- Clojerl, Clojure on BEAM, the Erlang virtual machine
- clojure-py, Clojure in pure Python
- Ferret, compiles to self-contained C++11 that can run on microcontrollers
- Joker, an interpreter and linter written in Go
- Las3r, a subset of Clojure that runs on the ActionScript Virtual Machine (the Adobe Flash Player platform)
- Pixie, Clojure-inspired Lisp dialect written in RPython
- Rouge, Clojure atop YARV in Ruby
With continued interest in functional programming, Clojure's adoption by software developers using the Java platform has continued to increase.
ThoughtWorks, while assessing functional programming languages for their Technology Radar, described Clojure as "a simple, elegant implementation of Lisp on the JVM" in 2010 and promoted its status to "ADOPT" in 2012.
In the "JVM Ecosystem Report 2018" (which was claimed to be "the largest survey ever of Java developers"), that was prepared in collaboration by Snyk and Java Magazine, ranked Clojure as the 2nd most used programming language on the JVM for "main applications".
It has also been used for creative computing, including visual art, music, games, and poetry.
Tooling for Clojure development has seen significant improvement over the years.
- Atom, with Chlorine
- Emacs, with CIDER
- IntelliJ IDEA, with Clojure-Kit or Cursive (a free license is available for non-commercial use)
- Light Table
- Vim, with fireplace.vim, vim-iced, or Conjure (Neovim only)
- Visual Studio Code, with Calva
Features by example
The following examples can be run in a Clojure REPL such as one started with the Clojure CLI tools or an online REPL such as one available on REPL.it.
Because of the strong emphasis on simplicity, typical Clojure programs consist of mostly functions and simple data structures (i.e., lists, vectors, maps, and sets):
Programming at the REPL
Note that, in the following examples, ;; starts a line comment and ;; => indicates the expected output:
Names at runtime
Unlike other runtime environments where names get compiled away, Clojure's runtime environment is easily introspectable using normal Clojure data structures:
Code as data (homoiconicity)
In the example below, we can see how easy it is to write code that modifies code itself:
Expressive operators for data transformation
The threading macros (->, ->>, and friends) can syntactically express the abstraction of piping a collection of data through a series of transformations:
This can also be achieved more efficiently using transducers:
Thread-safe management of identity and state
A thread-safe generator of unique serial numbers (though, like many other Lisp dialects, Clojure has a built-in gensym function that it uses internally):
An anonymous subclass of java.io.Writer that doesn't write to anything, and a macro using it to silence all prints within it:
Language interoperability with Java
Clojure was created from the ground up to embrace its host platforms as one of its design goals and thus provides excellent language interoperability with Java:
Software transactional memory
10 threads manipulating one shared data structure, which consists of 100 vectors each one containing 10 (initially sequential) unique numbers.
Each thread then repeatedly selects two random positions in two random vectors and swaps them.
All changes to the vectors occur in transactions by making use of Clojure's software transactional memory system:
Credits to the contents of this page go to the authors of the corresponding Wikipedia page: en.wikipedia.org/wiki/Clojure.