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)