all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Making alist that executes multiple commands
@ 2024-11-24 21:51 Heime via Users list for the GNU Emacs text editor
  2024-11-24 22:56 ` Stephen Berman
  0 siblings, 1 reply; 24+ messages in thread
From: Heime via Users list for the GNU Emacs text editor @ 2024-11-24 21:51 UTC (permalink / raw)
  To: Heime via Users list for the GNU Emacs text editor

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)))))




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

* Re: Making alist that executes multiple commands
  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
  0 siblings, 1 reply; 24+ messages in thread
From: Stephen Berman @ 2024-11-24 22:56 UTC (permalink / raw)
  To: Heime via Users list for the GNU Emacs text editor; +Cc: Heime

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



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

* Re: Making alist that executes multiple commands
  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-25  3:00     ` Stefan Monnier via Users list for the GNU Emacs text editor
  0 siblings, 2 replies; 24+ messages in thread
From: Heime via Users list for the GNU Emacs text editor @ 2024-11-24 23:13 UTC (permalink / raw)
  To: Stephen Berman; +Cc: Heime via Users list for the GNU Emacs text editor



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))))

What would you suggest for function commands requiring arguments, 
e.g. (alkotr-ar ar) and (alkotr-af af)?



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

* Re: Making alist that executes multiple commands
  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  3:00     ` Stefan Monnier via Users list for the GNU Emacs text editor
  1 sibling, 1 reply; 24+ messages in thread
From: Stephen Berman @ 2024-11-24 23:28 UTC (permalink / raw)
  To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor

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.

> 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)

Steve Berman



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

* Re: Making alist that executes multiple commands
  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
  0 siblings, 1 reply; 24+ messages in thread
From: Heime via Users list for the GNU Emacs text editor @ 2024-11-24 23:39 UTC (permalink / raw)
  To: Stephen Berman; +Cc: Heime via Users list for the GNU Emacs text editor






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))

> > 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?



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

* Re: Making alist that executes multiple commands
  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
  0 siblings, 1 reply; 24+ messages in thread
From: Heime via Users list for the GNU Emacs text editor @ 2024-11-25  1:05 UTC (permalink / raw)
  To: Heime; +Cc: Stephen Berman,
	Heime via Users list for the GNU Emacs text editor


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))
> 
> > > 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?

Does one use 

 (lookup-alist '( (ar (alkotr-ar arg-ar) (alkotr-af arg-af))
                  (go (alkotr-go arg-go) (alkotr-gc arg-gc))) ))





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

* Re: Making alist that executes multiple commands
  2024-11-24 23:13   ` Heime via Users list for the GNU Emacs text editor
  2024-11-24 23:28     ` Stephen Berman
@ 2024-11-25  3:00     ` Stefan Monnier via Users list for the GNU Emacs text editor
  1 sibling, 0 replies; 24+ messages in thread
From: Stefan Monnier via Users list for the GNU Emacs text editor @ 2024-11-25  3:00 UTC (permalink / raw)
  To: help-gnu-emacs

> Have thought about this.  Any criticisms about it?
>
>   '((ar . (lambda ()
>               (alkotr-ar)
>               (alkotr-af)))
>
>     (go   . (lambda ()
>               (alkotr-go)
>               (alkotr-gc))))

This uses lists (that happen to look like the source code of functions)
rather than actual functions.  The compiler won't see them, thus won't
compile them and won't give you warnings about dubious elements.

To use actual functions you need to do something like:

   `((ar . ,(lambda ()
              (alkotr-ar)
              (alkotr-af)))

     (go . ,(lambda ()
              (alkotr-go)
              (alkotr-gc))))


- Stefan




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

* Re: Making alist that executes multiple commands
  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
  0 siblings, 1 reply; 24+ messages in thread
From: Stephen Berman @ 2024-11-25  9:40 UTC (permalink / raw)
  To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor

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



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

* Re: Making alist that executes multiple commands
  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
  0 siblings, 1 reply; 24+ messages in thread
From: Heime via Users list for the GNU Emacs text editor @ 2024-11-25 13:10 UTC (permalink / raw)
  To: Stephen Berman; +Cc: Heime via Users list for the GNU Emacs text editor






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))
       (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.





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

* Re: Making alist that executes multiple commands
  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
  0 siblings, 1 reply; 24+ messages in thread
From: Stephen Berman @ 2024-11-25 14:58 UTC (permalink / raw)
  To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor

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



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

* Re: Making alist that executes multiple commands
  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
  0 siblings, 2 replies; 24+ messages in thread
From: Heime via Users list for the GNU Emacs text editor @ 2024-11-25 16:36 UTC (permalink / raw)
  To: Stephen Berman; +Cc: Heime via Users list for the GNU Emacs text editor






Sent with Proton Mail secure email.

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

> 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).

Right, that line should not be there.
 
> > (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

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?

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))))))





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

* Re: Making alist that executes multiple commands
  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
  1 sibling, 0 replies; 24+ messages in thread
From: Heime via Users list for the GNU Emacs text editor @ 2024-11-25 17:59 UTC (permalink / raw)
  To: Heime; +Cc: Stephen Berman,
	Heime via Users list for the GNU Emacs text editor


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)))))) ))






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

* Re: Making alist that executes multiple commands
  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
  1 sibling, 1 reply; 24+ messages in thread
From: Stephen Berman @ 2024-11-25 20:31 UTC (permalink / raw)
  To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor

On Mon, 25 Nov 2024 16:36:46 +0000 Heime <heimeborgia@protonmail.com> wrote:

> Sent with Proton Mail secure email.
>
> On Tuesday, November 26th, 2024 at 2:58 AM, Stephen Berman
> <stephen.berman@gmx.net> wrote:
>
>> 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).
>
> Right, that line should not be there.
>
>> > (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
>
> 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.

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



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

* Re: Making alist that executes multiple commands
  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
  0 siblings, 1 reply; 24+ messages in thread
From: Heime via Users list for the GNU Emacs text editor @ 2024-11-25 20:45 UTC (permalink / raw)
  To: Stephen Berman; +Cc: Heime via Users list for the GNU Emacs text editor


> > 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.
 
> 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")))




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

* Re: Making alist that executes multiple commands
  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
  0 siblings, 1 reply; 24+ messages in thread
From: Stephen Berman @ 2024-11-25 21:05 UTC (permalink / raw)
  To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor

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.

>> 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



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

* Re: Making alist that executes multiple commands
  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
  0 siblings, 1 reply; 24+ messages in thread
From: Heime via Users list for the GNU Emacs text editor @ 2024-11-25 21:18 UTC (permalink / raw)
  To: Stephen Berman; +Cc: Heime via Users list for the GNU Emacs text editor






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



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

* Re: Making alist that executes multiple commands
  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
  0 siblings, 1 reply; 24+ messages in thread
From: Stephen Berman @ 2024-11-25 21:27 UTC (permalink / raw)
  To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor

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



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

* Re: Making alist that executes multiple commands
  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
  0 siblings, 1 reply; 24+ messages in thread
From: Heime via Users list for the GNU Emacs text editor @ 2024-11-25 21:37 UTC (permalink / raw)
  To: Stephen Berman; +Cc: Heime via Users list for the GNU Emacs text editor






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.

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




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

* Re: Making alist that executes multiple commands
  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
  0 siblings, 1 reply; 24+ messages in thread
From: Stephen Berman @ 2024-11-25 21:45 UTC (permalink / raw)
  To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor

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



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

* Re: Making alist that executes multiple commands
  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
  0 siblings, 1 reply; 24+ messages in thread
From: Heime via Users list for the GNU Emacs text editor @ 2024-11-25 21:59 UTC (permalink / raw)
  To: Stephen Berman; +Cc: Heime via Users list for the GNU Emacs text editor






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.




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

* Re: Making alist that executes multiple commands
  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
  0 siblings, 1 reply; 24+ messages in thread
From: Stephen Berman @ 2024-11-25 22:09 UTC (permalink / raw)
  To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor

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

> 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.

It produces all combinations of function calls comprised of one of the
functions f and one of the arguments a; I did not mean to imply anything
else.  If it doesn't help with your use case, then of course don't use
it.

Steve Berman



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

* Re: Making alist that executes multiple commands
  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
  0 siblings, 1 reply; 24+ messages in thread
From: Heime via Users list for the GNU Emacs text editor @ 2024-11-25 22:50 UTC (permalink / raw)
  To: Stephen Berman; +Cc: Heime via Users list for the GNU Emacs text editor






Sent with Proton Mail secure email.

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

> On Mon, 25 Nov 2024 21:59:53 +0000 Heime heimeborgia@protonmail.com wrote:
> 
> > 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.
> 
> 
> It produces all combinations of function calls comprised of one of the
> functions f and one of the arguments a; I did not mean to imply anything
> else. If it doesn't help with your use case, then of course don't use
> it.

I worked through it a little bit

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

Which fails for + and -, Elisp requires at least two arguments 
to perform arithmetic operations. Since only a single argument 
is provided, this will result in an error.

So I have done 

(dolist (f '(+ - list))
  (dolist (a '(1 2 3))
    (dolist (b '(4 5 6))  ;; Adding another argument
      (message "Result of %s: %s" f (funcall f a b)))))

Producing

Result of +: 5
Result of +: 6
Result of +: 7
Result of +: 6
Result of +: 7
Result of +: 8
Result of +: 7
Result of +: 8
Result of +: 9
Result of -: -3
Result of -: -4
Result of -: -5
Result of -: -2
Result of -: -3
Result of -: -4
Result of -: -1
Result of -: -2
Result of -: -3
Result of list: (1 4)
Result of list: (1 5)
Result of list: (1 6)
Result of list: (2 4)
Result of list: (2 5)
Result of list: (2 6)
Result of list: (3 4)
Result of list: (3 5)
Result of list: (3 6)

It is a good exercise but not the kind of mixing I was thinking about.

I just have a set of commands that I want to run according to some setting
'argm or 'go.  Or do both with '(argm go).  That's all.  I think the lamdba
gets this done.  The arguments to any of the commands in the lambda can come
from external settings as well right, global variables and can introduce 
conditionals as well.  Which should be what I require.  Or would you know
about something else.  Is there ways the implementation can break?
 








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

* Re: Making alist that executes multiple commands
  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
  0 siblings, 1 reply; 24+ messages in thread
From: Stephen Berman @ 2024-11-25 23:11 UTC (permalink / raw)
  To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor

On Mon, 25 Nov 2024 22:50:03 +0000 Heime <heimeborgia@protonmail.com> wrote:

> Sent with Proton Mail secure email.
>
> On Tuesday, November 26th, 2024 at 10:09 AM, Stephen Berman
> <stephen.berman@gmx.net> wrote:
>
>> On Mon, 25 Nov 2024 21:59:53 +0000 Heime heimeborgia@protonmail.com wrote:
>>
>> > 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.
>>
>>
>> It produces all combinations of function calls comprised of one of the
>> functions f and one of the arguments a; I did not mean to imply anything
>> else. If it doesn't help with your use case, then of course don't use
>> it.
>
> I worked through it a little bit
>
> (dolist (f '(+ - list))
>   (dolist (a '(1 2 3))
>     (funcall f a)))
>
> Which fails for + and -, Elisp requires at least two arguments
> to perform arithmetic operations. Since only a single argument
> is provided, this will result in an error.

The functions `+' and `-' take any number of numbers (including none).
I don't know why you got an error; I don't:

(let (ret)
  (dolist (f '(+ - list))
    (dolist (a '(1 2 3))
      (push (funcall f a) ret)))
  ret)
==>
((3) (2) (1) -3 -2 -1 3 2 1)

[...]
> I just have a set of commands that I want to run according to some setting
> 'argm or 'go.  Or do both with '(argm go).  That's all.  I think the lamdba
> gets this done.  The arguments to any of the commands in the lambda can come
> from external settings as well right, global variables and can introduce
> conditionals as well.  Which should be what I require.  Or would you know
> about something else.  Is there ways the implementation can break?

I already said if it does what you want, that's fine.  I can't prove for
you it will always work, so if you find a case where it doesn't work,
feel free to show it.  Until then, I think this discussion has run its
course.

Steve Berman



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

* Re: Making alist that executes multiple commands
  2024-11-25 23:11                                       ` Stephen Berman
@ 2024-11-26  8:46                                         ` Heime via Users list for the GNU Emacs text editor
  0 siblings, 0 replies; 24+ messages in thread
From: Heime via Users list for the GNU Emacs text editor @ 2024-11-26  8:46 UTC (permalink / raw)
  To: Stephen Berman; +Cc: Heime via Users list for the GNU Emacs text editor






Sent with Proton Mail secure email.

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

> On Mon, 25 Nov 2024 22:50:03 +0000 Heime heimeborgia@protonmail.com wrote:
> 
> > Sent with Proton Mail secure email.
> > 
> > On Tuesday, November 26th, 2024 at 10:09 AM, Stephen Berman
> > stephen.berman@gmx.net wrote:
> > 
> > > On Mon, 25 Nov 2024 21:59:53 +0000 Heime heimeborgia@protonmail.com wrote:
> > > 
> > > > 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.
> > > 
> > > It produces all combinations of function calls comprised of one of the
> > > functions f and one of the arguments a; I did not mean to imply anything
> > > else. If it doesn't help with your use case, then of course don't use
> > > it.
> > 
> > I worked through it a little bit
> > 
> > (dolist (f '(+ - list))
> > (dolist (a '(1 2 3))
> > (funcall f a)))
> > 
> > Which fails for + and -, Elisp requires at least two arguments
> > to perform arithmetic operations. Since only a single argument
> > is provided, this will result in an error.
> 
> 
> The functions `+' and` -' take any number of numbers (including none).
> I don't know why you got an error; I don't:
> 
> (let (ret)
> (dolist (f '(+ - list))
> (dolist (a '(1 2 3))
> (push (funcall f a) ret)))
> ret)
> ==>
> 
> ((3) (2) (1) -3 -2 -1 3 2 1)

You are quite right.  I saw nil and thought it failed.  It did not
after doing

(dolist (f '(+ - list))
  (dolist (a '(1 2 3))
    (message "Result of %s: %s" f (funcall f a )) ))


 
> [...]
> 
> > I just have a set of commands that I want to run according to some setting
> > 'argm or 'go. Or do both with '(argm go). That's all. I think the lamdba
> > gets this done. The arguments to any of the commands in the lambda can come
> > from external settings as well right, global variables and can introduce
> > conditionals as well. Which should be what I require. Or would you know
> > about something else. Is there ways the implementation can break?
> 
> 
> I already said if it does what you want, that's fine. I can't prove for
> you it will always work, so if you find a case where it doesn't work,
> feel free to show it. Until then, I think this discussion has run its
> course.
> 
> Steve Berman

Right, I now understand the mixing of list of arguments with a list
of function names.  Such mixing is not what I had in mind.  Just wanted
a set a commands in a function which is not defined externally.



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

end of thread, other threads:[~2024-11-26  8:46 UTC | newest]

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

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.