Clojure Pretty-printing

Clojure programmers spend quite a bit of time looking at both code and data. Pretty-printing can make this information more readable, reducing both the effort involved and the opportunity for error, eg:

  • Sorting the keys in a hashmap or the values in a hashset
    can allow its contents to be inspected more quickly.

  • Adding white space (eg, line breaks and spaces)
    can make parallelism and structure more apparent.

Because code and data have different characteristics (eg, semantics), the specific techniques (and tools) used for them differs.

Code

???

Data

clojure.pprint

clojure.pprint is a Clojure-based "pretty printer" for data. Although clojure.pprint is distributed as part of Clojure, it is still under active development by Tom Faulhaber, who was also kind enough to help me create these web pages.

cl-format, which may be used separately of by means of clojure.pprint, is based on the Common Lisp "format" facility. It uses the XP algorithm to handle decision-making about line breaking and indentation, but has a more "Clojure-y" interface for writing custom dispatch routines.

The Clojure documentation is quite readable, but (admittedly) a bit incomplete in spots. More complete (but somewhat impenetrable) documentation is available for XP's Common Lisp version. This is my attempt at an accessible introductory reference to the Clojure version.

  • My snippets page shows how to obtain various formatting results from cl-format.

  • My pprint page discusses the relationship between pprint and cl-format.

Resources

Clojure

Common Lisp

These references document the Common Lisp "format" facility, so they are nearly correct as regards cl-format, etc.


This wiki page is maintained by Rich Morin, an independent consultant specializing in software design, development, and documentation. Please feel free to email comments, inquiries, suggestions, etc!

Topic revision: r5 - 29 Jan 2013, RichMorin
This site is powered by Foswiki Copyright © by the contributing authors. All material on this wiki is the property of the contributing authors.
Foswiki version v2.1.6, Release Foswiki-2.1.6, Plugin API version 2.4
Ideas, requests, problems regarding CFCL Wiki? Send us email