help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Making alist that executes multiple commands


From: Heime
Subject: Re: Making alist that executes multiple commands
Date: Mon, 25 Nov 2024 21:59:53 +0000





Sent with Proton Mail secure email.

On Tuesday, November 26th, 2024 at 9:45 AM, Stephen Berman 
<stephen.berman@gmx.net> wrote:

> 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


About your comment 

> That seems fine if the functions take no arguments, though probably not
> as flexible as looping over a list.

You provided the examples

(funcall 'alkotr-ar ar)
(funcall 'alkotr-ar af)

But I did not understand how to inceorporate this idea.  With
my lambda function, I can also pass arguments to my commands.

I did not understand the implication of the following in my case.

(dolist (f '(+ - list))
  (dolist (a '(1 2 3))
    (funcall f a)))

Thusly, I do not understand what "allow arguments to be freely combined"
actually means practically.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]