diff options
| -rw-r--r-- | src/hash-tables.lisp | 20 |
1 files changed, 1 insertions, 19 deletions
diff --git a/src/hash-tables.lisp b/src/hash-tables.lisp index 84ffbfe..4290387 100644 --- a/src/hash-tables.lisp +++ b/src/hash-tables.lisp | |||
| @@ -4,18 +4,9 @@ | |||
| 4 | (:documentation "Hash-table-oriented utilities.") | 4 | (:documentation "Hash-table-oriented utilities.") |
| 5 | (:use :c2cl) | 5 | (:use :c2cl) |
| 6 | (:import-from :alexandria :with-gensyms) | 6 | (:import-from :alexandria :with-gensyms) |
| 7 | (:export :alist->hash-table :gethash-lazy :plist->hash-table)) | 7 | (:export :gethash-lazy)) |
| 8 | (in-package :ukkoclot/hash-tables) | 8 | (in-package :ukkoclot/hash-tables) |
| 9 | 9 | ||
| 10 | (defun alist->hash-table (alist &rest args &key &allow-other-keys) | ||
| 11 | "Turn an association list into a hash table. | ||
| 12 | |||
| 13 | All key arguments are passed on to `make-hash-table'." | ||
| 14 | (let ((ht (apply #'make-hash-table args))) | ||
| 15 | (loop for (key . value) in alist do | ||
| 16 | (setf (gethash key ht) value)) | ||
| 17 | ht)) | ||
| 18 | |||
| 19 | (defmacro gethash-lazy (key hash-table default-lazy) | 10 | (defmacro gethash-lazy (key hash-table default-lazy) |
| 20 | "`gethash' alternative with lazily evaluated default value." | 11 | "`gethash' alternative with lazily evaluated default value." |
| 21 | (with-gensyms (res unique) | 12 | (with-gensyms (res unique) |
| @@ -24,12 +15,3 @@ All key arguments are passed on to `make-hash-table'." | |||
| 24 | (if (eq ,res ,unique) | 15 | (if (eq ,res ,unique) |
| 25 | ,default-lazy | 16 | ,default-lazy |
| 26 | ,res)))) | 17 | ,res)))) |
| 27 | |||
| 28 | (defun plist->hash-table (plist &rest args &key &allow-other-keys) | ||
| 29 | "Turn a property list into a hash table. | ||
| 30 | |||
| 31 | All key arguments are passed on to `make-hash-table'." | ||
| 32 | (let ((ht (apply #'make-hash-table args))) | ||
| 33 | (loop for (key value) on plist by #'cddr do | ||
| 34 | (setf (gethash key ht) value)) | ||
| 35 | ht)) | ||