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: Wed, 11 Oct 2017 09:42:47 -0700 (PDT) Message-ID: <3da0f75d-6000-410d-9e0b-ea293677b5ed@default> References: <54ecd1bb-0c84-4b0a-b19e-3a89cbe832bc@default> <87r2uce9u8.fsf@web.de> 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 1507740194 26372 195.159.176.226 (11 Oct 2017 16:43:14 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 11 Oct 2017 16:43:14 +0000 (UTC) Cc: 28753@debbugs.gnu.org To: Michael Heerdegen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Oct 11 18:43:10 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 1e2K63-0005aZ-Q0 for geb-bug-gnu-emacs@m.gmane.org; Wed, 11 Oct 2017 18:43:04 +0200 Original-Received: from localhost ([::1]:41876 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2K6B-000848-6j for geb-bug-gnu-emacs@m.gmane.org; Wed, 11 Oct 2017 12:43:11 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60476) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2K65-000841-GL for bug-gnu-emacs@gnu.org; Wed, 11 Oct 2017 12:43:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2K62-0004Y8-7t for bug-gnu-emacs@gnu.org; Wed, 11 Oct 2017 12:43:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:53976) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e2K62-0004Y4-4H for bug-gnu-emacs@gnu.org; Wed, 11 Oct 2017 12:43:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1e2K61-0007pn-S9 for bug-gnu-emacs@gnu.org; Wed, 11 Oct 2017 12:43:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Drew Adams Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 11 Oct 2017 16:43:01 +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.150774018030108 (code B ref 28753); Wed, 11 Oct 2017 16:43:01 +0000 Original-Received: (at 28753) by debbugs.gnu.org; 11 Oct 2017 16:43:00 +0000 Original-Received: from localhost ([127.0.0.1]:34424 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e2K5z-0007pY-Qt for submit@debbugs.gnu.org; Wed, 11 Oct 2017 12:43:00 -0400 Original-Received: from userp1040.oracle.com ([156.151.31.81]:20837) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e2K5y-0007pK-BJ for 28753@debbugs.gnu.org; Wed, 11 Oct 2017 12:42:58 -0400 Original-Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v9BGgpOO026873 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Oct 2017 16:42:52 GMT Original-Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id v9BGgoCt020966 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Oct 2017 16:42:51 GMT Original-Received: from abhmp0014.oracle.com (abhmp0014.oracle.com [141.146.116.20]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id v9BGgn6H018065; Wed, 11 Oct 2017 16:42:49 GMT In-Reply-To: X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9.1 (1003210) [OL 16.0.4588.0 (x86)] X-Source-IP: aserv0022.oracle.com [141.146.126.234] 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:138223 Archived-At: > > > Dunno whether functions like these might be useful. I use something > > > similar. If you think they're useful, consider adding them. > > > > I think something very similar is provided by map.el: `map-into'. >=20 > Good to know. Thx. Actually, going from alist to hash table doesn't look so useful with `map-into'. A caller should be able to specify the hash-table parameters (features), such as :test. `map-into' should probably accept additional, keyword args, which would be passed to `map--into-hash-table'. I imagine that `map-into' is intended to be extended to more than alists and hash tables eventually. Otherwise, dedicated functions for those two types, such as what I suggested, would make as much (or more) sense. Whether or not it will be so extended, it would be good for `map-into' to accept additional args that would be passed to the appropriate type-conversion helper functions. If we just allowed an &rest ARGS parameter, that would handle any types that might want to deal with additional args. But that would be less convenient than using keyword args for a hash table. We could I guess just pass ARGS along but define the helper function (e.g. `map--into-hash-table') using `cl-defun' with appropriate keyword args. IOW, at the `map-into' level nothing would be specified about ARGS, but each conversion helper could define what kinds of args it accepts. (There's also `&allow-other-keys', but probably it doesn't make much sense for `map-into' to define any keyword args.) In that case, the helper function should not be "internal", and the use of `make-hash-table' keyword args should be mentioned in its doc string. Although simple lookup in an Elisp alist typically uses only `assoc' or `assq' (or `rassoc' or `rassq'), a program that _uses_ an alist might well make use of a different equality test for its elements. It need not be limited to testing membership using `assoc' or `assq'. So while the alist to be converted to a hash table might not, itself, have any fancy notion of a :test function, the appropriate "equivalent" hash table in some context might well need to define a particular :test. This is why it makes sense to allow conversion to a hash table to give programmers an ability to specify :test (and other hash-table features). Note too that in Common Lisp `assoc' takes a :test arg. `map-into' is designed for alists that use `cl-assoc' as much as for those that use `assoc'. Unlike a hash table, however, an alist doesn't itself record ir require any particular :test function, so `map-into' can't transfer a hash-table :test to an alist that it produces from a hash table. So the existing `map-into' for conversion to an alist is good enough.