liveBook · Manning

Cl-format

As explained in Clojure: The Essential Reference

A Clojure pretty-printing function that formats text and values according to Common Lisp-style format directives.

cl-format is Clojure’s Common Lisp-style formatter for producing strings from values and formatting directives. It is useful when output needs more control than ordinary string construction, including decimal precision, padding, readable numbers, and conditional wording. section 1.5 section 18.1

Formatting a parsed balance

After parsing XML and converting the current balance to a number, (cl-format nil "~$" v) formats floating-point values while leaving other values unchanged. The resulting values can be combined with cleaned keys in a map.

How Clojure: The Essential Reference covers it

How deep it goes
Explains basic directives, conditional formatting, pluralization, and wrapping, while deferring complicated cases to explicit sequential processing.
Examples
Demonstrates decimal balances, numeric representations, pluralized sentences, conditional lists, and width-limited paragraphs.
What you can do after
Apply it via cl-format to generate formatted strings with numeric, conditional, grammatical, and line-wrapping behavior.
How it connects
Connects Common Lisp format, format, printf, Java String::format, string formatting, and pretty printing.

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.