all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
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 22:45:37 +0100	[thread overview]
Message-ID: <877c8r6l8e.fsf@rub.de> (raw)
In-Reply-To: <FhjFtEKjjMXA2FYo6LcbCjnjH0NGn_2TT_4Cqgu_dmHsU7Lc77Kgb9RdaNjgrbn1rV5CrsTFF3Jc3_R98q0KUcCLyq7s-gBFtFlb88uhHm0=@protonmail.com> (Heime's message of "Mon, 25 Nov 2024 21:37:12 +0000")

On Mon, 25 Nov 2024 21:37:12 +0000 Heime <heimeborgia@protonmail.com> wrote:

> Sent with Proton Mail secure email.
>
> On Tuesday, November 26th, 2024 at 9:27 AM, Stephen Berman
> <stephen.berman@gmx.net> wrote:
>
>> On Mon, 25 Nov 2024 21:18:28 +0000 Heime heimeborgia@protonmail.com wrote:
>>
>> > Sent with Proton Mail secure email.
>> >
>> > On Tuesday, November 26th, 2024 at 9:05 AM, Stephen Berman
>> > stephen.berman@gmx.net wrote:
>> >
>> > > On Mon, 25 Nov 2024 20:45:22 +0000 Heime heimeborgia@protonmail.com wrote:
>> > >
>> > > > > > Would be good to allow arguments to be freely combined.
>> > > > > > But how does one loop over lists of these arguments from the
>> > > > > > code you posted?
>> > > > >
>> > > > > Something like this, for example:
>> > > > >
>> > > > > (dolist (f '(+ - list))
>> > > > > (dolist (a '(1 2 3))
>> > > > > (funcall f a)))
>> > > > >
>> > > > > > I could have the following, but got some difficulties about
>> > > > > > how to execute each command with its arguments, in the way you
>> > > > > > suggest.
>> > > > > >
>> > > > > > (defun fpln-test (symbol-list)
>> > > > > > (let ( (lookup-alist '((ar ((alkotr-ar arg-this)
>> > > > > > (alkotr-af arg-that arg-other)))
>> > > > > > (go ((alkotr-go arg-dim)
>> > > > > > (alkotr-gc arg-dum arg-sum))) )) )
>> > > > > >
>> > > > > > (dolist (actm symbol-list)
>> > > > > > (let ((commands (cdr (assoc actm lookup-alist))))
>> > > > > > (while commands
>> > > > > > (dolist (cmd commands)
>> > > > > > (apply (car cmd) (cdr cmd)))
>> > > > > > (message "Key '%s' not found in lookup-alist" key))))))
>> > > > >
>> > > > > When I wrote "using a list of function calls as the value of each alist
>> > > > > element seems reasonable" I was assuming you wanted them in lambda
>> > > > > expressions, where they are evaluated, as in the example you gave
>> > > > > previously. You can't use a function call as the first argument of
>> > > > > `apply' or` funcall' because a function call (which is just a list whose
>> > > > > first element is a function) is not a function.
>> > > >
>> > > > Have been trying to handle your suggestion not to use a lambda, but to
>> > > > handle the general case of executing a sequence of commands in a list,
>> > > > each element being a command to run.
>> > >
>> > > Then you might try looping over lists of functions and arguments like in
>> > > the above schematic example I gave, though depending upon how you want
>> > > to combine the functions and arguments (e.g. if the functions don't all
>> > > have the same arity), this could become complicated. But without
>> > > specific examples of what you want to do I can't give more specific
>> > > advice.
>> >
>> > I have a sequence of commands for setting up a library component
>> >
>> > For instance
>> >
>> > ;; For option 'armg
>> > (add-to-list 'load-path (marnap-sec-fpln-waypt "NAPLN"))
>> > (require 'napyon)
>> >
>> > and
>> >
>> > ;; For option 'go
>> > (napyon 'go)
>> >
>> > Using lambda seems to offer more flexibility and maintainability, and
>> > extensibility. Perhaps contrary to your original point of view?
>>
>>
>> Well, these examples suggest that you indeed want different arguments
>> for each function, and moreover have groups of function calls, so yes,
>> lambda forms work well for those, and they are probably simpler for such
>> cases than looping over lists of functions and arguments.
>>
>> Steve Berman
>
> For what reasons have you suggested looping over lists of functions and
> arguments?  Would that have a list of function names, and a list with
> their arguments?
>
> You mentioned some advantages for working with arguments, but do not
> understand precisely what arguments to what were you referring to.

I mentioned freely combining functions and arguments and gave a
schematic example with nested dolist's; I haven't given it more thought
than that.

> With the lamdba version, I am getting the whole thing to work as intended.

Then be happy and continue to use it!

Steve Berman



  reply	other threads:[~2024-11-25 21:45 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
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 [this message]
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=877c8r6l8e.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.