From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: tomas@tuxteam.de Newsgroups: gmane.emacs.help Subject: Re: Output an alist from a function Date: Wed, 25 Sep 2024 06:39:40 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="ENLsQoAJR71dUa8s" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10654"; mail-complaints-to="usenet@ciao.gmane.io" Cc: help-gnu-emacs@gnu.org To: Heime Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed Sep 25 06:40:25 2024 Return-path: Envelope-to: geh-help-gnu-emacs@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 1stJpB-0002aE-3x for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 25 Sep 2024 06:40:25 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1stJoa-0007Sy-Ch; Wed, 25 Sep 2024 00:39:48 -0400 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 1stJoY-0007Sa-KA for help-gnu-emacs@gnu.org; Wed, 25 Sep 2024 00:39:46 -0400 Original-Received: from mail.tuxteam.de ([5.199.139.25]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1stJoW-0005Hh-4n for help-gnu-emacs@gnu.org; Wed, 25 Sep 2024 00:39:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tuxteam.de; s=mail; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject :Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=57Bd7fSb2DAkWaeUTSAsmhItpLB+DDDhMA2Xlp7fsEE=; b=vT8OG7ffjaa2r+bdIsZSUXiAGN ZtCJj/8ZHzR5Ao7CZ4M8JH3gQONYWTo1OR/1JDHKa2Vtf1mwIbsf1njOLi2CCsLb0nnGH51+BJXoD 5fyvwEL/Vv1RyvDYf75K0D399vN72XX8qYO8LCIKSb1sDziAsJ1+bp/37SAvu6pGteVpm0aZszEz+ TYnEhAWVvoaf6EflGMF1QJHrRc0m+OiOcCexF1B/g5tO9js3HU3rxsrlYLAf2sCR9U++u8S0sV1MP jBmtAV1qE9QbEROgupHoYRkHIXChLK0hydedAJGuXSOiVbZzinr1Lk3q8SQ3Qu9JDyHt2sebrM1hE ZGQHXymQ==; Original-Received: from tomas by mail.tuxteam.de with local (Exim 4.94.2) (envelope-from ) id 1stJoS-0005ey-WF; Wed, 25 Sep 2024 06:39:41 +0200 Content-Disposition: inline In-Reply-To: Received-SPF: pass client-ip=5.199.139.25; envelope-from=tomas@tuxteam.de; helo=mail.tuxteam.de 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, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:148063 Archived-At: --ENLsQoAJR71dUa8s Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable [I have re-added the mailing list in the CC] On Tue, Sep 24, 2024 at 09:28:24PM +0000, Heime wrote: > On Wednesday, September 25th, 2024 at 3:04 AM, tomas@tuxteam.de wrote: >=20 [...] > > I've some difficulties figuring out what your question is. > >=20 > > Is it that you want to write a function which "does the same" > > as output-table does, but for alist? >=20 >=20 > Precisely. The function for hash tables accepts a hash table as input > and outputs another hash table, where the keys correspond to directory > validation flags. I use maphash to iterate over the elements, and after > constructing the new table during the loop, I retrieve and return the > output-table after maphash completes. >=20 > Similarly, in the case of alists, the function takes an alist (where > each element is a key paired with a directory path) and returns a new > alist, where each key is associated with its respective directory > validation flag. This mirrors the behavior of the hash table > implementation but uses alists instead. >=20 > Currently, I am using mapcar to iterate over the alist and apply the > transformation via a lambda function. However, I am uncertain whether > simply invoking mapcar is enough to ensure the same structured output as > with hash tables. > With hash tables, maphash alone wasn=E2=80=99t sufficient - I needed to > explicitly construct and return an output hash table within the > function. My question is whether the same principle applies for alists: > do I need to construct and store the output alist in a temporary > structure, and then explicitly return it, akin to how I do with > output-table in the hash table case ? I'd, (once again) refer you to the corresponding function documentations: Mapcar collects the results of the function calls into a new list (if that function returns pairs, as yours does, you end up with an alist). Maphash "just" iterates over the key-value pairs. The naming is a bit inconsistent, yes. BTW: there is a function which "just" iterates over a list, "mapc". You see it in the code snippet I gave you. You use that one when you'd throw away the resulting list of "mapcar". I'd recommend to read more docs and to *make little experiments* (i.e. small programs of one, two or three lines) to check your understanding of what you have read. I see you stumbling time and again over very basic things, and you'd have far less busywork if you had those basic things at your disposal. Cheers --=20 t --ENLsQoAJR71dUa8s Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABECAB0WIQRp53liolZD6iXhAoIFyCz1etHaRgUCZvOUBQAKCRAFyCz1etHa Rs0LAJ9no1xj2weiTh24R2fUJEjMVZw/TgCfTuDhnHvoToy/dTpcG4RhQNcRWwU= =nx0Y -----END PGP SIGNATURE----- --ENLsQoAJR71dUa8s--