unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "Gerd Möllmann" <gerd.moellmann@gmail.com>
To: Shankar Rao <shankar.rao@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 15:19:46 +0100	[thread overview]
Message-ID: <m2r06ujf5p.fsf@gmail.com> (raw)
In-Reply-To: <CAGEgU=hS6qOFGxDHLzQZeB5O9SYVNh9EAeZJeN2etoweHAoh1Q@mail.gmail.com> (Shankar Rao's message of "Fri, 29 Nov 2024 14:47:40 +0100")

Shankar Rao <shankar.rao@gmail.com> writes:

> 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

Yes, I understood that, and I thought maybe you were asking this because
you were annoyed by having to write a lambda and so on, which using
cl-loop would avoid.

>
> (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?

I think Matthias said something like that already: It would be consing
up lists, that we otherwise don't need, and that's far from free.

My own gut feeling is that it might well be more expensive than maphash,
depending on the hash table size, of course. The least I would say is
that it's not a clear win.



      reply	other threads:[~2024-11-29 14:19 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
2024-11-29 14:19     ` Gerd Möllmann [this message]

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=m2r06ujf5p.fsf@gmail.com \
    --to=gerd.moellmann@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=shankar.rao@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).