From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Shankar Rao Newsgroups: gmane.emacs.devel Subject: Re: Is there utility in making hash-table-{keys, values} built-in functions? Date: Fri, 29 Nov 2024 14:47:40 +0100 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000ce51b706280d71a8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25054"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: =?UTF-8?Q?Gerd_M=C3=B6llmann?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Nov 29 16:45:06 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tH3B3-0006PY-9v for ged-emacs-devel@m.gmane-mx.org; Fri, 29 Nov 2024 16:45:05 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tH3AF-0007tZ-BR; Fri, 29 Nov 2024 10:44:15 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tH1Le-0006jH-A8 for emacs-devel@gnu.org; Fri, 29 Nov 2024 08:47:55 -0500 Original-Received: from mail-qt1-x832.google.com ([2607:f8b0:4864:20::832]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tH1Lc-0000zW-Bf for emacs-devel@gnu.org; Fri, 29 Nov 2024 08:47:53 -0500 Original-Received: by mail-qt1-x832.google.com with SMTP id d75a77b69052e-466966d8dbaso13634611cf.3 for ; Fri, 29 Nov 2024 05:47:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732888071; x=1733492871; darn=gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=j7CVpnCgWiO1a85/0eUOEMq8TK0rSCzyFLpwOLFeqh4=; b=Li53JpPj0bN+WuFcImw9iy3er7GTwlFYaF/BfYLw6rpdRS7f3ZL7uwqMoHOp+DeYG7 f0IesMqmnMn1h55UOcJffCVRbra4KhiaspnPyYfxQls8Kk/JS8veT5tvWlCbQjwinJem zfF9Rll7v6YOlK6ELJUUgZKgdhAwZIy7VYyNhSmyOU7un9NDp7rT4JIaWyFWdxCyIwIq TzwSE17iVS70jhvylbi6E7B8I6eLN+AmgcWvjCpB0xgU86/qKfG+QL6KoTsa0PGJ4jCa SqJnxHtgj2PIeXBktvq40c6KDQOZ4wUYefeNgMCXnbDH+FT+423LfgOHeq84ZTMGBA5q bITA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732888071; x=1733492871; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=j7CVpnCgWiO1a85/0eUOEMq8TK0rSCzyFLpwOLFeqh4=; b=kBhrkCqKJT9HzUjsMhxQS/pyKyoEjl9EBi4VywmeyL59Bnp+WnAcia0jixqkE9BiP0 UtjTsyBK2DsEZWvSUrVfFHURDow8yQJVGghapS9BiWFqRlP2vmHvELTFfJw0JYkZm/6o EgklR4RiIIiJ+aN7RQpIS6R+gMM4BCHo7aMzXfIE8G3YSuseS5dJ5Qr6JeFI/+XVYhuV 5VoMi0vpBRupAUw0YknNxktuR7EmwaRGBK3M040MB5CKmehKaH88IpXHbbawwxrTBiex zdgYH6+AHFfagtZRUBqiT5FnsJ4o97NltCyL7Ud9P6uzGmWMwCUt2UIbERBufa1/CPNw 7LwQ== X-Gm-Message-State: AOJu0Yz1Zd4Ul4BES5I7NpbQB1sJOdgHOtwuDdNS1rYT6RHdTK7Y/CJZ ZwNu/CMTI8vQ/nsE7npAagrnZcOb9DpMIcL5nLvocM1MmGwntX5gJ8yEkl2YQZbav8Hi9VRRzT+ 124naMLwOlbikolMlcvzc1muTa8c= X-Gm-Gg: ASbGncuDFlrLgNLpQLUre5GXxWo3ehXgm2iXAJWHQ3fmAFJt6Hmf9H/gx/WaUJo1pYM 6gWDuPukfMBU4u/0qdgVHIqNs4sna4XY= X-Google-Smtp-Source: AGHT+IED/ZMsmznJ78C3PfcLGjePRUFZ3c6kmA54UVbKTxCuTPGwiY7SVbfBdPlZlnIbsygE859/H2A5PNma6Dv8lQ8= X-Received: by 2002:a05:622a:15c7:b0:466:97cc:9338 with SMTP id d75a77b69052e-466b34d3252mr152904941cf.2.1732888069294; Fri, 29 Nov 2024 05:47:49 -0800 (PST) In-Reply-To: Received-SPF: pass client-ip=2607:f8b0:4864:20::832; envelope-from=shankar.rao@gmail.com; helo=mail-qt1-x832.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Fri, 29 Nov 2024 10:44:13 -0500 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:325855 Archived-At: --000000000000ce51b706280d71a8 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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=E2=80=AFPM Gerd M=C3=B6llmann wrote: > Shankar Rao 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) > > > --000000000000ce51b706280d71a8 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
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 se= em to be a way to iterate over a hash-table without either explicitly or im= plicitly using a lambda. For example, if we macro expand the following cl-l= oop

(cl-loop for key being hash-keys of tables= using (hash-values v)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0collect (func k= v))

we obtain:

(cl-b= lock nil
=C2=A0 (cl-block --cl-finish--
=C2=A0 =C2=A0 (maphash
=C2= =A0 =C2=A0 =C2=A0(lambda
=C2=A0 =C2=A0 =C2=A0 =C2=A0(key v)
=C2=A0 = =C2=A0 =C2=A0 =C2=A0(func k v))
=C2=A0 =C2=A0 =C2=A0tables))
=C2=A0 n= il)

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?

Shanka= r Rao

On Thu, Nov 28, 2024 at 7:40=E2=80=AFPM Gerd M=C3=B6llmann = <gerd.moellmann@gmail.com> wrote:
Sha= nkar Rao <sha= nkar.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

=C2=A0 for x being the hash-keys of something using (hash-value y)


--000000000000ce51b706280d71a8--