From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Andrea Corallo Newsgroups: gmane.emacs.devel Subject: new function proposal alist-to-hash Date: Thu, 03 Oct 2019 21:25:36 +0000 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="21325"; mail-complaints-to="usenet@blaine.gmane.org" To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Oct 03 23:32:38 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iG8iC-0005O7-Vf for ged-emacs-devel@m.gmane.org; Thu, 03 Oct 2019 23:32:37 +0200 Original-Received: from localhost ([::1]:40274 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iG8iB-0000TA-SC for ged-emacs-devel@m.gmane.org; Thu, 03 Oct 2019 17:32:35 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52698) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iG8ht-0000Si-Hr for emacs-devel@gnu.org; Thu, 03 Oct 2019 17:32:18 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iG8hs-0004UC-2t for emacs-devel@gnu.org; Thu, 03 Oct 2019 17:32:17 -0400 Original-Received: from mx.sdf.org ([205.166.94.20]:65532) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iG8hp-0004P9-S9 for emacs-devel@gnu.org; Thu, 03 Oct 2019 17:32:15 -0400 Original-Received: from sdf.org (IDENT:akrl@faeroes.freeshell.org [205.166.94.9]) by mx.sdf.org (8.15.2/8.14.5) with ESMTPS id x93LPa0m002345 (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits) verified NO) for ; Thu, 3 Oct 2019 21:25:36 GMT Original-Received: (from akrl@localhost) by sdf.org (8.15.2/8.12.8/Submit) id x93LPaKu012319; Thu, 3 Oct 2019 21:25:36 GMT X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 205.166.94.20 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:240531 Archived-At: --=-=-= Content-Type: text/plain Hi all, I'd like to propose a new simple function called alist-to-hash to make hash-tables from a-lists. In case something equivalent already exists I apologize. Please be patient, first contribution here :) I attach the patch. Best Regards Andrea PS Copyright paperwork are done. -- akrl@sdf.org --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Add-new-function-to-make-hash-tables-from-a-lists.patch >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 --=-=-=--