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: Thu, 12 Oct 2017 07:36:52 -0700 (PDT) Message-ID: <52a5f9a9-2fd9-49a6-9dd1-849f3c18b519@default> 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> 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 1507819117 27027 195.159.176.226 (12 Oct 2017 14:38:37 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 12 Oct 2017 14:38:37 +0000 (UTC) Cc: 28753@debbugs.gnu.org To: Nicolas Petton , Michael Heerdegen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Oct 12 16:38:30 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 1e2ecp-0004Um-Ij for geb-bug-gnu-emacs@m.gmane.org; Thu, 12 Oct 2017 16:38:15 +0200 Original-Received: from localhost ([::1]:45875 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2ecv-0001dN-4x for geb-bug-gnu-emacs@m.gmane.org; Thu, 12 Oct 2017 10:38:21 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44261) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2ecf-0001Yr-IT for bug-gnu-emacs@gnu.org; Thu, 12 Oct 2017 10:38:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2ecc-0003Sb-EX for bug-gnu-emacs@gnu.org; Thu, 12 Oct 2017 10:38:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:55759) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e2ecc-0003SV-AR for bug-gnu-emacs@gnu.org; Thu, 12 Oct 2017 10:38:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1e2ecc-00016b-1e for bug-gnu-emacs@gnu.org; Thu, 12 Oct 2017 10:38:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Drew Adams Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 12 Oct 2017 14:38: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.15078190264172 (code B ref 28753); Thu, 12 Oct 2017 14:38:01 +0000 Original-Received: (at 28753) by debbugs.gnu.org; 12 Oct 2017 14:37:06 +0000 Original-Received: from localhost ([127.0.0.1]:36207 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e2ebi-00015E-4G for submit@debbugs.gnu.org; Thu, 12 Oct 2017 10:37:06 -0400 Original-Received: from userp1040.oracle.com ([156.151.31.81]:36517) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e2ebg-00014h-KF for 28753@debbugs.gnu.org; Thu, 12 Oct 2017 10:37:05 -0400 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 v9CEatJG032574 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 12 Oct 2017 14:36:55 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 v9CEasId005412 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 12 Oct 2017 14:36:55 GMT Original-Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id v9CEarqk003360; Thu, 12 Oct 2017 14:36:53 GMT In-Reply-To: <87r2u8sdh5.fsf@petton.fr> 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: 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:138284 Archived-At: (Odd: I (and the bug-list?) don't seem to have received the reply from Michael that you quote below.) > Michael Heerdegen writes: > > > >> 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. > > > > Yeah, that's what I thought, too. >=20 > That's something I can easily add. `map-into' would then look > like the following `(defun map-into (map type &rest keywords))'. &rest keywords does not treat the keywords as keywords. That's why we have (CL has) &keys. (And &rest can be used together with &keys.) > However, `keywords' would be ignored when converting to > an alist. I'm not sure I like it. Converting to an alist is different from converting to a hash table. As I mentioned, in particular a hash table has, as part of its definition, a :test function etc. An alist does not. Even an alist in CL does not, even though CL at least allows :test with `assoc'. So a general function that wants to handle the two the same way is out of luck. The best it can do is just allow whatever keyword args or other args a given target representation construction function might need. But in that case it cannot actually control such args in the call. See the code I sent originally. Note too the optional arg USE-LAST-P that I provided for conversion of an alist to a hash-table. Unlike a hash table, an alist is often used in a way that allows multiple entries for the same key, and in particular in a way where the first entry shadows the other entries for the same key. That means that, for that common alist use case, it is likely that the conversion to a hash table would use only the first alist entry with a given key, ignoring any others. But because an alist can be used in multiple ways, including ways where the other entries (shadowed in the typical case) are relevant, and because the most common case among those cases is for the last entry, not the first one, to be most relevant, we provide arg USE-LAST-P. When that arg is non-nil the last alist entry for a given key is used for the hash table. (If you get a hash table from an alist then you necessarily get only one entry for a given key. So you do not really capture the alist in all its functionality. Presumably someone asking for such a conversion knows this. We could, instead of providing an optional arg such as USE-LAST-P, just expect the user who wants the hash table to have already removed all alist entries with the same key except for the entry s?he wants. But that can be a bit of a bother, and it's easy to provide USE-LAST-P as a convenience.) It's great to have abstract, general-purpose functions that handle maps, sequences, streams, etc. But not all such things are handled the same way in Lisp code. An alist is itself quite general, so it can be and is used in different ways in different programs. There is no single, simple mapping from an arbitrary alist to a hash table, I think. We can provide a general-purpose function that chooses just one kind of mapping from an alist to, e.g., a hash table. But I'm guessing that we should also provide a function that gives you more control over the conversion mapping. IOW, maybe both a `map-into' kind of general-purpose behavior and a more specific `alist-to-hash-table' kind of behavior. (But for the time being, `map-into' is only for list <-> hash table, so for the time being it seems less useful than the more specific function.)