Since clhs does not list the copy table function, I would suggest that maphash is the way to go.
(defun copy-table (table)
(let ((new-table (make-hash-table
:test (hash-table-test table)
:size (hash-table-size table))))
(maphash #'(lambda(key value)
(setf (gethash key new-table) value))
table)
new-table))
(let ((table (make-hash-table)))
(mapcar #'(lambda(arg argg)
(setf (gethash arg table) argg))
'(1 2 3 4) '(a b c d))
(format t "~a~%" table)
(format t "~a~%" (copy-table table)))
#<HASH-TABLE :TEST EQL :COUNT 4 {10063C7F13}>
#<HASH-TABLE :TEST EQL :COUNT 4 {10063C86D3}>
However, this function does not take into account the special configurations of the hash table, but as an example, it should be sufficient.
Sim source
share