From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.bugs Subject: bug#28753: 25.3; Functions to get alist from hash table and vice versa Date: Mon, 6 Nov 2017 18:24:26 -0800 (PST) Message-ID: References: <54ecd1bb-0c84-4b0a-b19e-3a89cbe832bc@default> <87r2uce9u8.fsf@web.de> <3da0f75d-6000-410d-9e0b-ea293677b5ed@default> <87wp4038m0.fsf@web.de> <87r2u8sdh5.fsf@petton.fr> <52a5f9a9-2fd9-49a6-9dd1-849f3c18b519@default> <87wp326hla.fsf@users.sourceforge.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1510021513 8669 195.159.176.226 (7 Nov 2017 02:25:13 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 7 Nov 2017 02:25:13 +0000 (UTC) Cc: Michael Heerdegen , Nicolas Petton , 28753@debbugs.gnu.org To: Noam Postavsky Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Nov 07 03:25:05 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eBtZY-0001sH-Gy for geb-bug-gnu-emacs@m.gmane.org; Tue, 07 Nov 2017 03:25:04 +0100 Original-Received: from localhost ([::1]:51090 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBtZf-0007PY-PY for geb-bug-gnu-emacs@m.gmane.org; Mon, 06 Nov 2017 21:25:11 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51769) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBtZZ-0007PT-RB for bug-gnu-emacs@gnu.org; Mon, 06 Nov 2017 21:25:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eBtZW-0004pP-Ml for bug-gnu-emacs@gnu.org; Mon, 06 Nov 2017 21:25:05 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:46306) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eBtZW-0004pE-IU for bug-gnu-emacs@gnu.org; Mon, 06 Nov 2017 21:25:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1eBtZW-00081l-7v for bug-gnu-emacs@gnu.org; Mon, 06 Nov 2017 21:25:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Drew Adams Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 07 Nov 2017 02:25:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 28753 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 28753-submit@debbugs.gnu.org id=B28753.151002148330828 (code B ref 28753); Tue, 07 Nov 2017 02:25:02 +0000 Original-Received: (at 28753) by debbugs.gnu.org; 7 Nov 2017 02:24:43 +0000 Original-Received: from localhost ([127.0.0.1]:54987 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eBtZD-00081A-4i for submit@debbugs.gnu.org; Mon, 06 Nov 2017 21:24:43 -0500 Original-Received: from userp1040.oracle.com ([156.151.31.81]:17755) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eBtZA-00080v-Or for 28753@debbugs.gnu.org; Mon, 06 Nov 2017 21:24:41 -0500 Original-Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id vA72OXi9031407 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 7 Nov 2017 02:24:34 GMT Original-Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id vA72OWrw031253 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 7 Nov 2017 02:24:33 GMT Original-Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id vA72OVt4025528; Tue, 7 Nov 2017 02:24:31 GMT In-Reply-To: <87wp326hla.fsf@users.sourceforge.net> X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9.1 (1003210) [OL 16.0.4600.0 (x86)] X-Source-IP: userv0021.oracle.com [156.151.31.71] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:139548 Archived-At: > > Any news on this? There is no general, abstract > > solution proposed, so far, to meet the needs met > > by the specific alist <-> hash-table code I sent. >=20 > Did you have any comments for my proposal in #29? >=20 > https://urldefense.proofpoint.com/v2/url?u=3Dhttps- > 3A__debbugs.gnu.org_cgi_bugreport.cgi-3Fbug-3D28753- > 2329&d=3DDwIBAg&c=3DRoP1YumCXCgaWHvlZYR8PZh8Bv7qIrMUB65eapI_JnE&r=3DkI3P6= ljGv6CTH > IKju0jqInF6AOwMCYRDQUmqX22rJ98&m=3D2PshIV1HLbvhys07NQMj0gaYobwyLDaPs6zHJY= zxwD > Y&s=3D30GvxP6lcqjxDwNDmk0njIsHZRQE1V1VGEA4JNZLf60&e=3D I don't see a complete proposal there. Your solution is apparently to punt, telling users to first create the hash table they need and then call a function that injects the alist key+value entries into that existing table. I think that's less clear than the function I provided. And in particular it does not provide a USE-LAST possibility. Does it? Would you be adding an optional such arg to `map--into-existing-hash-table', to handle this? Would the default behavior of that function use only the first entry with a given key, as is typical for an alist? If you show how to achieve all of what this definition achieves, then I guess it would be OK - provided its doc makes it just as clear as is clear for this function how to get specific alist-to-hash-table mappings: (cl-defun alist-to-hash-table (alist &optional use-last-p &key (test 'eql) weakness (size 65) (rehash-size 1.5) (rehash-threshold 0.= 8)) "Create and return a hash table created from ALIST. By default, if the same alist key is used in more than one alist entry then only the first entry is used for the hash table. Non-nil USE-LAST-P means override this to use only the last entry for a given key. See `make-hash-table' for the keyword arguments you can use and their default values." (let ((ht (make-hash-table :test test :weakness weakness :size size :rehash-size rehash-size :rehash-threshold rehash-threshold)) key val) (dolist (key.val alist) (setq key (car key.val) val (cdr key.val)) (when (or use-last-p (not (gethash key ht))) (puthash key val ht))) ht)) Users shouldn't have to reinvent that by figuring out how they might achieve its possibilities using `map-into'. You would presumably start by defining `map--into-existing-hash-table'. (Why would that function be "internal", BTW?)