ELisp: Pretty Print Hash Table 🚀

By Xah Lee. Date: . Last updated: .

Here's a function that prints each key value pair by a line.

(defun xah-print-hash (hashtable)
  "Prints the hashtable, each line is printed as key → val.
URL `http://xahlee.info/emacs/emacs/elisp_print_hash_table.html'
Version: 2024-04-20"
  (maphash
   (lambda (k v)
     (princ (format "%s → %s" k v))
     (princ "\n"))
   hashtable
   ))

;; test

(setq xx (make-hash-table :test 'equal))
(puthash "joe" 19 xx)
(puthash "jane" 20 xx)
(puthash "carrie" 17 xx)
(puthash "liz" 21 xx)

(xah-print-hash xx)

;; joe → 19
;; jane → 20
;; carrie → 17
;; liz → 21

Emacs Lisp Hash Table