>From e2bca29d6fca8c1a40e57526432cb4ce29b2245b Mon Sep 17 00:00:00 2001 From: Andrea Corallo Date: Thu, 3 Oct 2019 22:56:43 +0200 Subject: [PATCH] Add new function to make hash-tables from a-lists * lisp/emacs-lisp/subr-x.el (alist-to-hash): New function make hash-tables from a-lists. * etc/NEWS: Announce it. --- etc/NEWS | 3 +++ lisp/emacs-lisp/subr-x.el | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/etc/NEWS b/etc/NEWS index c8cc753..f4924ba 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -24,6 +24,9 @@ applies, and please also update docstrings as needed. * Installation Changes in Emacs 27.1 +** New function 'alist-to-hash'. +Create recursively hash-tables from a-lists. + ** Emacs now uses GMP, the GNU Multiple Precision library. By default, if 'configure' does not find a suitable libgmp, it arranges for the included mini-gmp library to be built and used. diff --git a/lisp/emacs-lisp/subr-x.el b/lisp/emacs-lisp/subr-x.el index 3da5241..e67f59b 100644 --- a/lisp/emacs-lisp/subr-x.el +++ b/lisp/emacs-lisp/subr-x.el @@ -204,6 +204,18 @@ hash-table-values "Return a list of values in HASH-TABLE." (cl-loop for v being the hash-values of hash-table collect v)) +(defun alist-to-hash (a-list &rest keyword-args) + "Create recursively an hash table from A-LIST. +KEYWORD-ARGS parameters are forwarded to `make-hash-table'." + (cl-loop with h = (apply #'make-hash-table keyword-args) + for (k . v) in a-list + do (puthash k + (if (consp v) + (apply #'alist-to-hash v keyword-args) + v) + h) + finally (return h))) + (defsubst string-empty-p (string) "Check whether STRING is empty." (string= string "")) -- 2.7.4