[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:18:28 +0000 |
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?
Because I do not have to use explicit command lists. Lambdas also
allow dynamic and conditional logic.
> > > On Mon, 25 Nov 2024 17:59:22 +0000 Heime heimeborgia@protonmail.com wrote:
> > >
> > > > I get error when calling (marnap '(armg go))
> > > >
> > > > That is I get message "ACTM Unrecognised: 'armg"
> > > >
> > > > (defun marnap (&optional actm-service)
> > > >
> > > > (let ( (lookup-alist '((armg ((add-to-list 'load-path
> > > > (marnap-sec-fpln-waypt "NAPLN"))
> > > > (require 'napyon)))
> > > >
> > > > (go ((napyon 'go))) )) )
> > > >
> > > > (dolist (actm actm-service)
> > > > (let ((fnlist (cdr (assoc actm lookup-alist))))
> > > > (while fnlist
> > > > (dolist (cmd fnlist)
> > > > (if (functionp (car cmd))
> > > > (apply (car cmd) (cdr cmd))
> > > > (message "ACTM Unrecognised: '%s\n" actm)))))) ))
> > >
> > > This is for the same reason as above: the first invocation of `(car cmd)'
> > > returns` (add-to-list 'load-path (marnap-sec-fpln-waypt
> > > "NAPLN"))', which is a function call, not a function.
> > >
> > > Steve Berman
> >
> > Have put another question to not complicate this discussion.
> > Would it make sense to execute the function calls with eval.
> >
> > Still that is also giving me problems with
> >
> > (invalid-function (add-to-list 'load-path (marnap-sec-fpln-waypt "NAPLN")))
>
>
> This is probably because you have something like this:
>
> (eval ((add-to-list 'load-path (marnap-sec-fpln-waypt "NAPLN")) ...))
>
> That is, you're applying eval to a list, and eval treats a list like a
> function call, so it expects the first element to be (or evaluate to) a
> function, but `(add-to-list 'load-path (marnap-sec-fpln-waypt "NAPLN"))'
> is, again, not a function but a function call.
>
> Steve Berman
- Re: Making alist that executes multiple commands, (continued)
- Re: Making alist that executes multiple commands, Heime, 2024/11/24
- Re: Making alist that executes multiple commands, Heime, 2024/11/24
- Re: Making alist that executes multiple commands, Stephen Berman, 2024/11/25
- Re: Making alist that executes multiple commands, Heime, 2024/11/25
- Re: Making alist that executes multiple commands, Stephen Berman, 2024/11/25
- Re: Making alist that executes multiple commands, Heime, 2024/11/25
- Re: Making alist that executes multiple commands, Heime, 2024/11/25
- Re: Making alist that executes multiple commands, Stephen Berman, 2024/11/25
- Re: Making alist that executes multiple commands, Heime, 2024/11/25
- Re: Making alist that executes multiple commands, Stephen Berman, 2024/11/25
- Re: Making alist that executes multiple commands,
Heime <=
- Re: Making alist that executes multiple commands, Stephen Berman, 2024/11/25
- Re: Making alist that executes multiple commands, Heime, 2024/11/25
- Re: Making alist that executes multiple commands, Stephen Berman, 2024/11/25
- Re: Making alist that executes multiple commands, Heime, 2024/11/25
- Re: Making alist that executes multiple commands, Stephen Berman, 2024/11/25
- Re: Making alist that executes multiple commands, Heime, 2024/11/25
- Re: Making alist that executes multiple commands, Stephen Berman, 2024/11/25
- Re: Making alist that executes multiple commands, Heime, 2024/11/26
- Re: Making alist that executes multiple commands, Stefan Monnier, 2024/11/24