From: Stephen Berman <stephen.berman@gmx.net>
To: Heime <heimeborgia@protonmail.com>
Cc: Heime via Users list for the GNU Emacs text editor
<help-gnu-emacs@gnu.org>
Subject: Re: Making alist that executes multiple commands
Date: Mon, 25 Nov 2024 15:58:37 +0100 [thread overview]
Message-ID: <87wmgr742q.fsf@rub.de> (raw)
In-Reply-To: <Di6M6YaJB1Xs1HcPtSrqd7supIAoqdNLCyscI3_nwHjimAuB6FWMHumj0CbkCdTnqYWdMxzqkB775Z-zThF0VzXOod3ap7GHw7-RJQxsWwg=@protonmail.com> (Heime's message of "Mon, 25 Nov 2024 13:10:57 +0000")
On Mon, 25 Nov 2024 13:10:57 +0000 Heime <heimeborgia@protonmail.com> wrote:
> Sent with Proton Mail secure email.
>
> On Monday, November 25th, 2024 at 9:40 PM, Stephen Berman
> <stephen.berman@gmx.net> wrote:
>
>> On Mon, 25 Nov 2024 01:05:10 +0000 Heime heimeborgia@protonmail.com wrote:
>>
>> > On Monday, November 25th, 2024 at 11:39 AM, Heime via Users list for the GNU
>> > Emacs text editor help-gnu-emacs@gnu.org wrote:
>> >
>> > > Sent with Proton Mail secure email.
>> > >
>> > > On Monday, November 25th, 2024 at 11:28 AM, Stephen Berman
>> > > stephen.berman@gmx.net wrote:
>> > >
>> > > > On Sun, 24 Nov 2024 23:13:51 +0000 Heime heimeborgia@protonmail.com wrote:
>> > > >
>> > > > > On Monday, November 25th, 2024 at 10:56 AM, Stephen Berman
>> > > > > stephen.berman@gmx.net wrote:
>> > > > >
>> > > > > > On Sun, 24 Nov 2024 21:51:38 +0000 Heime via Users list for the GNU Emacs
>> > > > > > text editor help-gnu-emacs@gnu.org wrote:
>> > > > > >
>> > > > > > > What changes can I make to the following to allow me to execute more
>> > > > > > > commands than just one (as in alkotr-ar and alkotr-go).
>> > > > > > >
>> > > > > > > For ar I want to call functions alkotr-ar and alkotr-af
>> > > > > > >
>> > > > > > > (let ( (lookup-alist
>> > > > > > > '((ar . alkotr-ar)
>> > > > > > > (go . alkotr-go))))
>> > > > > > >
>> > > > > > > (dolist (actm symbol-list)
>> > > > > > > (let ((func (cdr (assoc actm lookup-alist))))
>> > > > > > > (if func
>> > > > > > > (funcall func)
>> > > > > > > (message "ACTM Unrecognised: %s%s" "'" actm)))))
>> > > > > >
>> > > > > > Something like this:
>> > > > > >
>> > > > > > (let ((symbol-list '(ar go))
>> > > > > > (lookup-alist '((ar alkotr-ar alkotr-af)
>> > > > > > (go alkotr-go alkotr-gc))))
>> > > > > > (dolist (actm symbol-list)
>> > > > > > (let ((fnlist (cdr (assoc actm lookup-alist))))
>> > > > > > (while fnlist
>> > > > > > (let ((func (pop fnlist)))
>> > > > > > (if (functionp func)
>> > > > > > (funcall func)
>> > > > > > (message "ACTM Unrecognised: %s%s" "'" actm)))))))
>> > > > > >
>> > > > > > Steve Berman
>> > > > >
>> > > > > Have thought about this. Any criticisms about it?
>> > > > >
>> > > > > '((ar . (lambda ()
>> > > > > (alkotr-ar)
>> > > > > (alkotr-af)))
>> > > > >
>> > > > > (go . (lambda ()
>> > > > > (alkotr-go)
>> > > > > (alkotr-gc))))
>> > > >
>> > > > That seems fine if the functions take no arguments, though probably not
>> > > > as flexible as looping over a list.
>> > >
>> > > Could you explain? Can't I do
>> > >
>> > > (go . (lambda ()
>> > > (alkotr-go go)
>> > > (alkotr-gc gc))
>>
>>
>> Yes (but as Stefan Monnier pointed out and I overlooked, you have to
>> evaluate the lambda expressions). I was just referring to the specific
>> function calls you used.
>>
>> > > > > What would you suggest for function commands requiring arguments,
>> > > > > e.g. (alkotr-ar ar) and (alkotr-af af)?
>> > > >
>> > > > (funcall 'alkotr-ar ar)
>> > > > (funcall 'alkotr-ar af)
>> > >
>> > > How would the above solution fit with argument incorporation within
>> > > lookup-alist?
>>
>>
>> I'm not sure what you're asking here.
>>
>> > Does one use
>> >
>> > (lookup-alist '( (ar (alkotr-ar arg-ar) (alkotr-af arg-af))
>> > (go (alkotr-go arg-go) (alkotr-gc arg-gc))) ))
>>
>>
>> Use it for what?
>>
>> Steve Berman
>
> (defun fpln-test (symbol-list)
^^^^^^^^^^^
> (let ((symbol-list '(ar go))
^^^^^^^^^^^^^^^^^^^^^^
It doesn't make sense to pass the value of a variable as a function
argument and also unconditionally bind the same variable in the body of
the function before it's used (unless the use is outside of the scope of
the binder, which it isn't here).
> (lookup-alist '((ar alkotr-ar alkotr-af)
> (go alkotr-go alkotr-gc))))
>
> (dolist (actm symbol-list)
> (let ((fnlist (cdr (assoc actm lookup-alist))))
> (while fnlist
> (let ((func (pop fnlist)))
> (if (functionp func)
> (funcall func)
> (message "ACTM Unrecognised: %s%s" "'" actm))))))))
>
> You suggested the use use of
>
> (funcall 'alkotr-ar ar)
> (funcall 'alkotr-ar af)
>
> Where are they to be introduced?
>
> I was planning to introduce the arguments in the lookup-alist.
> So that for ar one can include arguments to alkotr-ar and
> alkotr-af.
If each argument is passed to only one function, then using a list of
function calls as the value of each alist element seems reasonable. If
the functions and arguments can be (more) freely combined, looping over
lists of these seems programmatically cleaner. But either way should
work.
Steve Berman
next prev parent reply other threads:[~2024-11-25 14:58 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-24 21:51 Making alist that executes multiple commands Heime via Users list for the GNU Emacs text editor
2024-11-24 22:56 ` Stephen Berman
2024-11-24 23:13 ` Heime via Users list for the GNU Emacs text editor
2024-11-24 23:28 ` Stephen Berman
2024-11-24 23:39 ` Heime via Users list for the GNU Emacs text editor
2024-11-25 1:05 ` Heime via Users list for the GNU Emacs text editor
2024-11-25 9:40 ` Stephen Berman
2024-11-25 13:10 ` Heime via Users list for the GNU Emacs text editor
2024-11-25 14:58 ` Stephen Berman [this message]
2024-11-25 16:36 ` Heime via Users list for the GNU Emacs text editor
2024-11-25 17:59 ` Heime via Users list for the GNU Emacs text editor
2024-11-25 20:31 ` Stephen Berman
2024-11-25 20:45 ` Heime via Users list for the GNU Emacs text editor
2024-11-25 21:05 ` Stephen Berman
2024-11-25 21:18 ` Heime via Users list for the GNU Emacs text editor
2024-11-25 21:27 ` Stephen Berman
2024-11-25 21:37 ` Heime via Users list for the GNU Emacs text editor
2024-11-25 21:45 ` Stephen Berman
2024-11-25 21:59 ` Heime via Users list for the GNU Emacs text editor
2024-11-25 22:09 ` Stephen Berman
2024-11-25 22:50 ` Heime via Users list for the GNU Emacs text editor
2024-11-25 23:11 ` Stephen Berman
2024-11-26 8:46 ` Heime via Users list for the GNU Emacs text editor
2024-11-25 3:00 ` Stefan Monnier via Users list for the GNU Emacs text editor
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=87wmgr742q.fsf@rub.de \
--to=stephen.berman@gmx.net \
--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.