___ ___
/\ \ /\ \
/::\ \ /::\ \
/:/\:\ \ /:/\:\ \
/::\~\:\ \ /::\~\:\ \
/:/\:\ \:\__\ /:/\:\ \:\__\
\/__\:\/:/ / \/__\:\/:/ /
\::/ / \::/ /
\/__/ \/__/
A fast, single-namespace, no-dependency Clojure pretty-printer for data (not code).
fipp.edn/pprint
and ~85x–16x faster than clojure.pprint/pprint
at Fipp's benchmark)clojure.pprint/pprint
clojure.pprint/pprint
, ~12x fewer than fipp.edn/pprint
)cl-format
Either:
Copy src/me/flowthing/pp.clj
into your codebase and rename the namespace to avoid conflicts, or:
Pull it in as a Git dep:
io.github.eerohele/pp {:git/tag "...", :git/sha "..."}
Then:
user=> (require '[me.flowthing.pp :as pp])
nil
user=> (pp/pprint {:a 1 :b 2 :c 3 :d 4})
{:a 1, :b 2, :c 3, :d 4}
nil
user=> (pp/pprint {:a 1 :b 2 :c 3 :d 4} {:max-width 10})
{:a 1,
:b 2,
:c 3,
:d 4}
nil
user=> (clojure.repl/doc pp/pprint)
...
Even though pp is not meant for formatting code, having it format the source of every var in the clojure.core
namespace and comparing the output to that of clojure.pprint/pprint
is a good exercise because clojure.core
has a large variety of data structures and nesting levels.
In that exercise, every difference between the outputs of me.flowthing.pp/pprint
and clojure.pprint/pprint
is one where clojure.pprint/pprint
doesn't make full use of the 72 character line width (default for both clojure.pprint/pprint
and pp) even though it could.
Also, unlike clojure.pprint/pprint
, pp prints records like pr
does:
user=> (defrecord R [x])
user.R
nil
user=> (prn (->R 1))
#user.R{:x 1}
nil
user=> (pp/pprint (->R 1))
#user.R{:x 1}
nil
user=> (clojure.pprint/pprint (->R 1))
{:x 1}
nil
In addition, there are one or two other minor, insignificant differences in where clojure.pprint/pprint
and pp insert line breaks. If you spot these and they bother you, file an issue.
print-method
for pretty much everything except Clojure's built-in collection types. This means pp prints things like time-literals the same way as clojure.pprint/pprint
.(fipp.edn/pprint '@foo)
as (clojure.core/deref foo)
; pp, like clojure.pprint/pprint
, prints it as @foo
. The same with quote
/'
, var
/#'
, and unquote
/~
.The algorithm pp uses is based on the ideas in Pretty-Printing, Converting List to Linear Structure by Ira Goldstein (Artificial Intelligence, Memo No. 279 in Massachusetts Institute of Technology A.I. Laboratory, February 1973).
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close