Common Lisp Library for Pretty Printing? e.g. pretty print a nested hash table

If you considering writing it yourself, here is a starting point using print-object. It is not implementation independent, but this works at least in LispWorks and SBCL.

(defmethod print-object ((object hash-table) stream)
  (format stream "#HASH{~{~{(~a : ~a)~}~^ ~}}"
          (loop for key being the hash-keys of object
                using (hash-value value)
                collect (list key value))))

First, CL does not have a "collection" type.

Second, some (most?) CL implementations will print hash tables with content if you set *print-array* to t.

Third, if your CL implementation does not do that, you can easily whip up your own, based on, say, hash-table->alist.

Tags:

Common Lisp