Code: Select all
(defmacro populated-hash-table
((;; &optional
;; hash-function weakness synchronized
&key
(test ''eq)
(size 1000)
(rehash-size 1.5)
(rehash-threshold 1))
&body body)
`(let ((table (make-hash-table
;; ,hash-function ,weakness ,synchronized
:test ,test
:size ,size
:rehash-size ,rehash-size
:rehash-threshold ,rehash-threshold
)))
,@(mapcar #'(lambda (x)
`(setf (gethash ',(car x) table)
,(cdr x))) body)
table))
(populated-hash-table (:test #'equal) (a . 1) (b . 2) (c . 3))
(let ((test-table (populated-hash-table (:test #'equal) (a . 1) (b . 2) (c . 3))))
(loop for x being the hash-keys in test-table
for y being the hash-values in test-table
do (format t "~s => ~s~&" x y)))