From: Drew Adams <drew.adams@oracle.com>
To: Noam Postavsky <npostavs@users.sourceforge.net>
Cc: Michael Heerdegen <michael_heerdegen@web.de>,
Nicolas Petton <nicolas@petton.fr>,
28753@debbugs.gnu.org
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) [thread overview]
Message-ID: <f934e294-9c59-4928-b806-26e877414eb0@default> (raw)
In-Reply-To: <87wp326hla.fsf@users.sourceforge.net>
> > 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.
>
> Did you have any comments for my proposal in #29?
>
> https://urldefense.proofpoint.com/v2/url?u=https-
> 3A__debbugs.gnu.org_cgi_bugreport.cgi-3Fbug-3D28753-
> 2329&d=DwIBAg&c=RoP1YumCXCgaWHvlZYR8PZh8Bv7qIrMUB65eapI_JnE&r=kI3P6ljGv6CTH
> IKju0jqInF6AOwMCYRDQUmqX22rJ98&m=2PshIV1HLbvhys07NQMj0gaYobwyLDaPs6zHJYzxwD
> Y&s=30GvxP6lcqjxDwNDmk0njIsHZRQE1V1VGEA4JNZLf60&e=
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?)
next prev parent reply other threads:[~2017-11-07 2:24 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
[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 [this message]
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f934e294-9c59-4928-b806-26e877414eb0@default \
--to=drew.adams@oracle.com \
--cc=28753@debbugs.gnu.org \
--cc=michael_heerdegen@web.de \
--cc=nicolas@petton.fr \
--cc=npostavs@users.sourceforge.net \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.