Elisp: Pretty Print Hash Table

By Xah Lee. Date: . Last updated: .
(progn
  (setq xx (make-hash-table :test 'equal))
  (puthash "joe" 19 xx)
  (puthash "jane" 20 xx)
  (puthash "liz" 21 xx))

;; pretty print hashtable, each pair on a line.
;; first convert to alist by map-pairs.
;; then, mapconcat into one string, then print.
;; this is more efficient then calling print on each pair.
(print
 (mapconcat
  (lambda (x) (format "%s → %s" (car x) (cdr x)))
  (map-pairs xx) "\n"))
;; "joe → 19
;; jane → 20
;; liz → 21"