From: Jean Louis <bugs@gnu.support>
To: Joel Reicher <joel.reicher@gmail.com>
Cc: Heime via Users list for the GNU Emacs text editor
<help-gnu-emacs@gnu.org>, Heime <heimeborgia@protonmail.com>
Subject: Re: Using hash table to apply command sequence with arguments
Date: Mon, 23 Dec 2024 09:10:20 +0300 [thread overview]
Message-ID: <Z2j-zOw74CklQp3P@lco2> (raw)
In-Reply-To: <86frmfj3d3.fsf@gmail.com>
* Joel Reicher <joel.reicher@gmail.com> [2024-12-22 15:43]:
> Heime via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
> writes:
>
> > How can use a hash table to execute a sequence of commands, possibly
> > with arguments.
>
> Hash tables aren't sequences.
There is no statement above that hash table is sequence.
Sure! It is possible to use hash table as a database which can accept functions and their arguments, which then later need to be executed.
Though you would need to have some time of sorting, if you need the order of execution.
(setq my-hash (make-hash-table))
(puthash 'tetris nil my-hash)
(puthash 'message '("Hello there again") my-hash)
(defun my-run-sequence-of-commands-by-hash (hash)
(let ((keys (reverse (hash-table-keys my-hash))) ;; it is questionable if there is any order with hashes
(continue t))
(while (and keys continue)
(let* ((function (pop keys))
(args (gethash function hash)))
(apply function args)
(setq continue (y-or-n-p "Do you wish to continue with the function list?"))))))
(my-run-sequence-of-commands-by-hash my-hash)
I have https://gnu.support/files/emacs/packages/rcd-hash-edit.el hash
library which allows hashes to be visually edited, saved, and loaded
interactively or programmatically. That would mean that using hashes
to record which functions to execute could be made permanent and saved
on the disk, for the later execution.
Emacs Lisp package `rcd-hash-edit.el`:
https://hyperscope.link/3/7/6/6/1/Emacs-Lisp-package-rcd-hash-edit-37661.html
--
Jean Louis
prev parent reply other threads:[~2024-12-23 6:10 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-25 12:05 Using hash table to apply command sequence with arguments Heime via Users list for the GNU Emacs text editor
2024-12-22 12:42 ` Joel Reicher
2024-12-23 6:10 ` Jean Louis [this message]
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Z2j-zOw74CklQp3P@lco2 \
--to=bugs@gnu.support \
--cc=heimeborgia@protonmail.com \
--cc=help-gnu-emacs@gnu.org \
--cc=joel.reicher@gmail.com \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).