From: tomas@tuxteam.de
To: Heime <heimeborgia@protonmail.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Output an alist from a function
Date: Wed, 25 Sep 2024 06:39:40 +0200 [thread overview]
Message-ID: <ZvOUDK5QwyhBDnuI@tuxteam.de> (raw)
In-Reply-To: <XNzsgrVzyJ1cGGJ6ClcRSUwsUKUwGIyfaLcQMYzA2NfLsrKKUehR3x9I_RW89PN-924bDrJimliX5QaXk-nwfjKXlk9t-vnMkFb4iJxG7WM=@protonmail.com>
[-- Attachment #1: Type: text/plain, Size: 2528 bytes --]
[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 <tomas@tuxteam.de> wrote:
>
[...]
> > I've some difficulties figuring out what your question is.
> >
> > Is it that you want to write a function which "does the same"
> > as output-table does, but for alist?
>
>
> 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.
>
> 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.
>
> 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’t 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
--
t
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
next prev parent reply other threads:[~2024-09-25 4:39 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-23 21:42 Output an alist from a function Heime
2024-09-24 15:04 ` tomas
2024-09-24 21:28 ` Heime
2024-09-25 4:39 ` tomas [this message]
2024-09-25 20:30 ` Heime
2024-09-26 4:43 ` tomas
2024-09-26 8:23 ` Heime
2024-09-26 9:01 ` tomas
2024-09-26 20:58 ` Heime
2024-09-24 16:19 ` Stephen Berman
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZvOUDK5QwyhBDnuI@tuxteam.de \
--to=tomas@tuxteam.de \
--cc=heimeborgia@protonmail.com \
--cc=help-gnu-emacs@gnu.org \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.