From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?utf-8?Q?Gerd_M=C3=B6llmann?= Newsgroups: gmane.emacs.devel Subject: Re: Is there utility in making hash-table-{keys, values} built-in functions? Date: Fri, 29 Nov 2024 15:19:46 +0100 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3384"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: emacs-devel@gnu.org To: Shankar Rao Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Nov 29 15:21: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 1tH1rm-0000mA-So for ged-emacs-devel@m.gmane-mx.org; Fri, 29 Nov 2024 15:21:06 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tH1qo-0000QX-Lp; Fri, 29 Nov 2024 09:20:07 -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 1tH1qm-0000QL-C6 for emacs-devel@gnu.org; Fri, 29 Nov 2024 09:20:04 -0500 Original-Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tH1qj-0006Rd-37 for emacs-devel@gnu.org; Fri, 29 Nov 2024 09:20:04 -0500 Original-Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-38232cebb0cso1520162f8f.1 for ; Fri, 29 Nov 2024 06:19:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732889988; x=1733494788; darn=gnu.org; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=lUlmzOXz60t0r6TDKumICCQjcRfXOCsb5UJCaJXZD7o=; b=LE49uNV87W8/CS0D9uBOCsFLY8k/8Ac14RMC30o2XGiqjVDyqXjfknDs0sN/Iie35E tL9YwJJNXsDOa/eB1m7ZhmmoyibiBZ3W4wpIyVwWXW4S8sHVC87Z0yN6PQmPdUVfAFUk u/oCI6gwMh6cLfOV7k78wophlB41Xf6L7JJFdiAI6hwxjopEUWQ9pX5Dp4AhZD3deLAP F1GsyfqKjRA+x5HqcgWNnT0rwHvro3QdE23o+R1wAZa8rZOHi8f90vL1MN0CtB3U9ab+ +GcHRyCD+y8Xg12qQ58lI2yiAAW/hKoUsGMHAQY6/xem+ogvQOGp3DN1uILLkif+MuW2 eCWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732889988; x=1733494788; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=lUlmzOXz60t0r6TDKumICCQjcRfXOCsb5UJCaJXZD7o=; b=eJovX1Bs7dkX9+1pHlXs/QweRgxp9p/u8mDTo/H3z7fGMEztyLwo3Usue5u2l5mFFz luKjWsnsk1apJoabT6MTH8K/ST75zfYKIJzJAXBykWRDnfXns7LndO4xGQu1eW3h29bi WNVOhYvqgcuhNpFtuJBv39rTaDaKogxQBuwAiLKm1Omdb5aAJTKsRQ7yDbKofK1kSAt1 andIaIkC76RyexsP4K21xlOdXRlTwtuGXPuRgWn+rptip0Mb7i1aNBisvTyvW6dAL62E z+JmQE+A+XZitusaYWv8v89ryZgWHMMBCQyfgfl4BZET+N77UQKM/FEJNnLSkQg1549z RhdQ== X-Gm-Message-State: AOJu0Ywppz8/jBV6qE7NjIBJ/WezNzqNL9aJosvUEKSvmwvpeqhdo3KL 9RPaCutECyYOfzivs5kjZslk6TL3cYmjSZfamp2ibrecUOFm8vrfUTFd1A== X-Gm-Gg: ASbGncvlH1T+V+sp6YmhtZfKwtvRvWdvzA6GElKwb3SdADlKqpP2NkPnse7QXk65IUU +bPbVAOjBMMv1C7gzEoQSdkAbEsRr5MTDoHF5i0kNHZNdi8h6LfpLK4Prb1zR3gRz1kPobuawsb mJ3Uh5NWrbqYBUmEbl6Ic4yg0/YR2Zjj5bvnFA+vwnpPyD3UjvH4Nts18aqPaklUX4rnu7nLycH w4OSxMsa6whUlS3uDWkKXvCXIoNm4OKN3xomZRkcHDqvfqSoPwNXrH/eIYd3QUWbuVvXwQBELsl pX51ytSIW9uXp70Av3MFo+4adMVWep8cWd1GVl6XzdjLrLyr6x8jHAIB/Ew= X-Google-Smtp-Source: AGHT+IEPiIaaX1RraAW2UigfMRdCc5l/6rAXpxT3WJWQREYEWgCJUn2T8a5FXa5NKvLDGDSLCenXxQ== X-Received: by 2002:a05:6000:401f:b0:382:4503:7283 with SMTP id ffacd0b85a97d-385c6eb6dd7mr11778328f8f.9.1732889987513; Fri, 29 Nov 2024 06:19:47 -0800 (PST) Original-Received: from pro2 (p200300e0b72c7500442ac98b932af1d6.dip0.t-ipconnect.de. [2003:e0:b72c:7500:442a:c98b:932a:f1d6]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-385df74157asm1496118f8f.0.2024.11.29.06.19.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Nov 2024 06:19:47 -0800 (PST) In-Reply-To: (Shankar Rao's message of "Fri, 29 Nov 2024 14:47:40 +0100") Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=gerd.moellmann@gmail.com; helo=mail-wr1-x42c.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, 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-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:325853 Archived-At: Shankar Rao 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.