unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Using hash table to apply command sequence with arguments
@ 2024-11-25 12:05 Heime via Users list for the GNU Emacs text editor
  2024-12-22 12:42 ` Joel Reicher
  0 siblings, 1 reply; 3+ messages in thread
From: Heime via Users list for the GNU Emacs text editor @ 2024-11-25 12:05 UTC (permalink / raw)
  To: Heime via Users list for the GNU Emacs text editor

How can use a hash table to execute a sequence of commands, 
possibly with arguments.  Here I am decoupling the action 
from the conditions.  Would this be a good strategy?

(defun fpln-test (actm-service)

  (let ((actm-table (make-hash-table :test 'eq)))

    ;; Put entry to actm-table
    (puthash 'armg (lambda ()
                     (alkotr-ar ar)
                     (alkotr-af af)))
              actm-table)

    ;; Put entry to actm-table
    (puthash 'go   (lambda ()
                     (require 'alkotr)
                     (alkotr-ignition gf))
             actm-table)

    ;; Map values from collection with lookup from hash table
    (mapc (lambda (actm)
            (let ((action (gethash actm actm-table)))
              (if action
                   (funcall action)
                (message "[marshal-falkotr]\n%s%s\n"
                         "  └── ACTM Unrecognised:" "'" actm))))
          actm-service)))



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Using hash table to apply command sequence with arguments
  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
  0 siblings, 1 reply; 3+ messages in thread
From: Joel Reicher @ 2024-12-22 12:42 UTC (permalink / raw)
  To: Heime via Users list for the GNU Emacs text editor; +Cc: Heime

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.

Regards,

        - Joel



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Using hash table to apply command sequence with arguments
  2024-12-22 12:42 ` Joel Reicher
@ 2024-12-23  6:10   ` Jean Louis
  0 siblings, 0 replies; 3+ messages in thread
From: Jean Louis @ 2024-12-23  6:10 UTC (permalink / raw)
  To: Joel Reicher; +Cc: Heime via Users list for the GNU Emacs text editor, Heime

* 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



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-12-23  6:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 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).