liveBook · Manning

Standard library

As explained in Clojure: The Essential Reference

A standard library is the collection of reusable code packaged with a programming language and made available as part of its normal distribution.

A standard library is reusable code available with a language’s normal distribution. In Clojure, it provides ready-made functions and macros for recurring work, so an application can spend less code on plumbing and more on its own requirements. Small library functions can also be composed into solutions that are easier to read and maintain. section 1.9 section 1.1 section 1.5

Clojure’s standard library has two main parts:

  • `clojure.core` supplies the main public API, including arithmetic, conditionals, and functions for working with other functions. Its definitions are available without an explicit namespace reference. section 1.4
  • Other namespaces shipped with Clojure group related facilities, such as `clojure.string`, `clojure.xml`, and `clojure.test`. Depending on how a function is accessed, you may use a qualified name or bring its namespace into scope with `require`. section 1.4 section 22.0

The Java SDK is readily accessible through Clojure’s Java interoperability, but it is distinct from these two Clojure-shipped parts. For example, Clojure provides common arithmetic operators while Java supplies many additional math functions. Public library definitions are generally intended for use, though a function marked `alpha` may change. section 1.4 section 5.1

Turn an XML balance into a readable report

Suppose XML supplies fields such as `lastAccess` and `currentBalance`. A report must separate the words in those names and format the balance to two decimal places. Rather than hand-writing character handling and numeric padding, combine `clojure.string/split`, `capitalize`, and `join` for the names; `clojure.pprint/cl-format` for currency; and `zipmap` to pair formatted names with values. `with-open` manages the input stream, while a threading macro keeps the parsing steps readable. The library does not replace the report’s requirements—it supplies focused pieces for implementing them. section 1.5

The boundary between language and library is not always obvious: Clojure builds many familiar constructs, including some conditionals and loops, from library macros atop special forms. To use the library well, look beyond a function’s name: compare similar functions, try examples in the REPL, and test corner cases such as `nil` or unexpected argument types. section 3.0 section 1.7

How Clojure: The Essential Reference covers it

How deep it goes
Defines the Clojure library’s boundaries and demonstrates composition, while leaving detailed treatment of Java SDK facilities aside.
Examples
Uses an XML balance report to compare hand-written formatting with composed string, formatting, and collection functions.
What it assumes
Assumes some Clojure familiarity and encourages learning unfamiliar functions through documentation, REPL experiments, and edge-case tests.
What you can do after
Apply it via Clojure namespaces to assemble readable solutions from existing functions instead of reimplementing routine operations.
How it connects
Connects namespaces and macros to Java interoperability, persistent collections, and concurrency.

Also explained in

Compare how 7 books explain standard library →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Clojure: The Essential Reference. The section links point to the parts of the book it draws on.