Emacs Lisp: 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 key, val"
   (lambda (k v)
     (princ (format "%s , %s" k v))
     (princ "\n"))

;; 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)
;; prints
;; joe , 19
;; jane , 20
;; carrie , 17
;; liz , 21

Emacs Lisp Hash Table

Lisp Basics

Lisp Data Structure
Lisp Symbol
Lisp Misc
Working with Elisp