ArticleslgStudy

computer science

Clojure

Clojure is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Clojure rather than just read about it. In short: Clojure (, like closure) is a dynamic and functional dialect of the programming language Lisp on the Java platform. Like most other Lisps, Clojure's syntax is built on S-expressions that are first parsed into data structures by a Lisp reader before being compiled.

Clojure — main illustration
Clojure — illustration

Key takeaways

  • Clojure belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Clojure to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Clojure from memory before moving on to harder problems.

Reference excerpt

Clojure (, like closure) is a dynamic and functional dialect of the programming language Lisp on the Java platform. Like most other Lisps, Clojure's syntax is built on S-expressions that are first parsed into data structures by a Lisp reader before being compiled. Clojure's reader supports literal syntax for maps, sets, and vectors along with lists, and these are compiled to the mentioned structures directly. Clojure treats code as data and has a Lisp macro system. 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. Clojure advocates immutability and immutable data structures and encourages programmers to be explicit about managing identity and its states. 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. While its type system is entirely dynamic, recent efforts have also sought the implementation of a dependent type system. The language was created by Rich Hickey in the mid-2000s, originally for the Java platform; the language has since been ported to other platforms, such as JavaScript and .NET. Hickey continues to lead development of the language as its benevolent dictator for life.

History

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 started working on Clojure in 2005 and spent about two and a half years working on Clojure before releasing it publicly in October 2007, much of that time working exclusively on Clojure with no outside funding. Stephanie Hickey, his wife, helped to design the language by being an active listener and participating in discussions without writing any code. At the end of this time, Hickey sent an email announcing the language to some friends in the Common Lisp community. Clojure's name, according to Hickey, is a word play 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.

Design Rich Hickey developed Clojure because he wanted a modern Lisp for functional programming, symbiotic with the established Java platform, and designed for concurrency. He has also stressed the importance of simplicity in programming language design and software architecture, advocating for loose coupling, polymorphism via protocols and type classes instead of inheritance, stateless functions that are namespaced instead of methods or replacing syntax with data. 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. Clojure runs on the Java platform and as a result, integrates with Java and fully supports calling Java code from Clojure, and Clojure code can be called from Java, too. The community uses tools such as Clojure command-line interface (CLI) or Leiningen for project automation, providing support for Maven integration. These tools handle project package management and dependencies and are configured using Clojure syntax. As a Lisp dialect, Clojure supports functions as first-class objects, a read–eval–print loop (REPL), and a macro system. Clojure's Lisp macro system is very similar to that of Common Lisp with the exception that Clojure's version of the backquote (termed "syntax quote") qualifies symbols with their namespace. 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. Clojure has support for lazy sequences and encourages the principle of immutability and persistent data structures. As a functional language, emphasis is placed on recursion and higher-order functions instead of side-effect-based looping. 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. For parallel and concurrent programming Clojure provides software transactional memory, a reactive agent system, and channel-based concurrent programming. Clojure 1.7 introduced reader conditionals by allowing the embedding of Clojure, ClojureScript and ClojureCLR code in the same namespace. Transducers were added as a method for composing transformations. Transducers enable higher-order functions such as map and fold to generalize over any source of input data. While traditionally these functions operate on sequences, transducers allow them to work on channels and let the user define their own models for transduction.

Extensible Data Notation Extensible Data Notation, or edn, is a subset of the Clojure language intended as a data transfer format. It can be used to serialize and deserialize Clojure data structures, and Clojure itself uses a superset of edn to represent programs. edn is used in a similar way to JSON or XML, but has a relatively large list of built-in elements, shown here with examples:

… excerpt ends here. Continue reading the full article.

Illustrations

Clojure illustration
Clojure: Rich Hickey, creator of Clojure
Rich Hickey, creator of Clojure

Worked examples

Example 1 — a first encounter with Clojure

Start with the simplest possible case. Write down what Clojure claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Clojure before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Clojure ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Clojure

In research
Clojure appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Clojure in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Clojure is common in secondary-school and first-year university syllabi. It links to neighbouring topics 2007 software, Cross-platform free software, Cross-platform software, so understanding it makes those chapters shorter.
In everyday life
Look for Clojure outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Clojure” →

How to study Clojure in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Clojure means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Clojure out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Clojure in simple terms?

Clojure (, like closure) is a dynamic and functional dialect of the programming language Lisp on the Java platform. Like most other Lisps, Clojure's syntax is built on S-expressions that are first parsed into data structures by a Lisp reader before being compiled.

Why does Clojure matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Clojure?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Clojure.

Tags

  • 2007 software
  • Cross-platform free software
  • Cross-platform software
  • Dynamic programming languages
  • Dynamically typed programming languages
  • Extensible syntax programming languages
  • Functional languages
  • High-level programming languages
  • JVM programming languages
  • Lisp (programming language)
  • Lisp programming language family
  • Multi-paradigm programming languages

Keep exploring