From: Shankar Rao <shankar.rao@gmail.com>
To: "Gerd Möllmann" <gerd.moellmann@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: Is there utility in making hash-table-{keys, values} built-in functions?
Date: Fri, 29 Nov 2024 14:47:40 +0100 [thread overview]
Message-ID: <CAGEgU=hS6qOFGxDHLzQZeB5O9SYVNh9EAeZJeN2etoweHAoh1Q@mail.gmail.com> (raw)
In-Reply-To: <m24j3rcict.fsf@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1500 bytes --]
This isn't about syntax, as changing hash-table-{keys,values} to be
built-in functions wouldn't change their syntax.
I was curious about this because there doesn't seem to be a way to iterate
over a hash-table without either explicitly or implicitly using a lambda.
For example, if we macro expand the following cl-loop
(cl-loop for key being hash-keys of tables using (hash-values v)
collect (func k v))
we obtain:
(cl-block nil
(cl-block --cl-finish--
(maphash
(lambda
(key v)
(func k v))
tables))
nil)
Most languages that provide a hash-table data structure provide methods for
directly accessing the hash keys and values. I'm trying to understand if it
would be beneficial for elisp to provide these as well. Would it provide a
significant enough speed boost for code that frequently iterates over hash
keys/values? Is there some complication implementing these functions in C
directly?
Shankar Rao
On Thu, Nov 28, 2024 at 7:40 PM Gerd Möllmann <gerd.moellmann@gmail.com>
wrote:
> Shankar Rao <shankar.rao@gmail.com> writes:
>
> > Hello all,
> >
> > I noticed that the functions hash-table-keys and hash-table-values are
> > just wrappers around maphash. This means that there is no way to
> > iterate over a hash-table without using a lambda.
>
> If this is about syntax, cl-loop has support for hash tables. For
> example
>
> for x being the hash-keys of something using (hash-value y)
>
>
>
[-- Attachment #2: Type: text/html, Size: 2092 bytes --]
next prev parent reply other threads:[~2024-11-29 13:47 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-28 11:53 Is there utility in making hash-table-{keys, values} built-in functions? Shankar Rao
2024-11-28 17:31 ` Mattias Engdegård
2024-11-29 14:25 ` Shankar Rao
2024-11-29 22:05 ` Tomas Hlavaty
2024-11-28 18:40 ` Gerd Möllmann
2024-11-29 13:47 ` Shankar Rao [this message]
2024-11-29 14:19 ` Gerd Möllmann
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='CAGEgU=hS6qOFGxDHLzQZeB5O9SYVNh9EAeZJeN2etoweHAoh1Q@mail.gmail.com' \
--to=shankar.rao@gmail.com \
--cc=emacs-devel@gnu.org \
--cc=gerd.moellmann@gmail.com \
/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).