From: Drew Adams <drew.adams@oracle.com>
To: Michael Heerdegen <michael_heerdegen@web.de>
Cc: 28753@debbugs.gnu.org
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) [thread overview]
Message-ID: <3da0f75d-6000-410d-9e0b-ea293677b5ed@default> (raw)
In-Reply-To: <ff48c465-086a-4c86-9ce8-8298324a45c3@default>
> > > 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'.
>
> 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.
next prev parent reply other threads:[~2017-10-11 16:42 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-09 0:25 bug#28753: 25.3; Functions to get alist from hash table and vice versa Drew Adams
2017-10-09 13:20 ` Michael Heerdegen
2017-10-09 14:11 ` Drew Adams
2017-10-11 16:42 ` Drew Adams [this message]
[not found] ` <87wp4038m0.fsf@web.de>
2017-10-12 13:27 ` Nicolas Petton
2017-10-12 13:46 ` Michael Heerdegen
2017-10-12 14:36 ` Drew Adams
2017-11-06 16:19 ` Drew Adams
2017-11-07 0:46 ` Noam Postavsky
2017-11-07 2:24 ` Drew Adams
2017-11-07 2:51 ` Noam Postavsky
2017-11-07 13:28 ` Michael Heerdegen
2017-12-30 20:40 ` Philipp Stephani
2017-12-30 21:08 ` Drew Adams
2017-12-30 21:15 ` Philipp Stephani
2017-10-12 15:56 ` Noam Postavsky
2017-10-12 13:30 ` Nicolas Petton
2022-04-22 13:18 ` Lars Ingebrigtsen
2022-04-22 15:21 ` Drew Adams
2017-12-30 21:26 ` Philipp Stephani
2017-12-31 0:01 ` Drew Adams
2018-03-04 19:17 ` Philipp Stephani
2018-03-05 0:01 ` Drew Adams
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3da0f75d-6000-410d-9e0b-ea293677b5ed@default \
--to=drew.adams@oracle.com \
--cc=28753@debbugs.gnu.org \
--cc=michael_heerdegen@web.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).