From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stephen Berman Newsgroups: gmane.emacs.help Subject: Re: Making alist that executes multiple commands Date: Mon, 25 Nov 2024 21:31:13 +0100 Message-ID: <87jzcr6ooe.fsf@rub.de> References: <87wmgss0k6.fsf@gmx.net> <87sergrz2j.fsf@gmx.net> <87mshn8xd8.fsf@gmx.net> <87wmgr742q.fsf@rub.de> Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26355"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Heime via Users list for the GNU Emacs text editor To: Heime Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Mon Nov 25 21:31:55 2024 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tFfkQ-0006iI-Qz for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 25 Nov 2024 21:31:54 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tFfjv-0002EZ-Ej; Mon, 25 Nov 2024 15:31:23 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tFfjt-0002Do-Ee for help-gnu-emacs@gnu.org; Mon, 25 Nov 2024 15:31:21 -0500 Original-Received: from mout.gmx.net ([212.227.17.22]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tFfjr-0001eQ-4M for help-gnu-emacs@gnu.org; Mon, 25 Nov 2024 15:31:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1732566676; x=1733171476; i=stephen.berman@gmx.net; bh=Lw9B98Tmi7NKisKLz/KxBXkQfOVaZL4DwYS8UXx2Les=; h=X-UI-Sender-Class:From:To:Cc:Subject:In-Reply-To:References:Date: Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=TxJ44P5Vxacx/xWOFW/ToIlCqGenWWlcG+d7Hfctst1PdyqgsiB8ydQEzXzmZdbm 2e28HOv2MXO7G7sywz1RldtHSqRL/4ZReTbCnfrYR60dw+hMAQEcA8yu3NiIhjlTX 1U2QQjIzZGVU3z4xl0Mh9u9UvSdv19bkG0jgIyoXDe9F7W3udHSI8vmMothqx0bsB x6OZ+AVGEaUXvfkuUt+X8KsTCkjJ40xTWdBtBMGx7b52/8kh2Y8qugql0KLxbKLTz frtWrg7mqV1xqdDyBcD6cQljm0x86570B0HbfhVgCbqxLBIoXC5aWH7T9wgoPbtaD FjvpKDoa+B+adgtsow== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Original-Received: from strobelfssd ([88.130.50.169]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MIMbU-1tRmgy1U7I-007f5c; Mon, 25 Nov 2024 21:31:16 +0100 In-Reply-To: (Heime's message of "Mon, 25 Nov 2024 16:36:46 +0000") X-Provags-ID: V03:K1:VTJ7OvIvR9UCfmmwFVUcahdF6+2dJ0vc24fP5FO+nJWpmeWZeAa +6c0Ti8NYE/mxHxhy+M+ch+pfLirjnrwsGxuURvGj8UfpGqsOFj/Kcs6uzpl+SqupojVMak cBb2H/GbjaikgE2FlWhTLrOV63IELc2RKsMjTik2K+S42A7WllWCXJR5f50i9kg4UdKX5mk 6ynUpEI265+ZrwJg6H18g== UI-OutboundReport: notjunk:1;M01:P0:go/u/5vqM7I=;1kRVRLvZbGb3hQIutwKwR78Fv3P vgfXt4cHkWo5+yo9hx3FsBLzDacCOQOQrjvf8hLZJEqdqsHNheXIfoqJMGMuUsfKFQMuKwSxd ks2Fb5xsD+cabCapa7lWOb4ddo/+S9+113PyPuL8gYZiXyEXxFlxJwuFHgexn/v84PqJOgENl u0ZHsl4hWHbpEIu/67XqddUSfttTsNhd0covvRXyMjXsb9n/zBp6dqS5tNDYC/mx3/d1JZ10o L5f/dckYBSBFOIXkfS0P6U8u1PzcOItCWduFVZ+NBiYpF/SdAwY8oE/J59pauWIxHgCPACAhn Yl09/ecg5wMLGz3JN0/69xe0wynYeYfQHB9oDm57t7NUYsi5f0GC/zHUHJtoECehyKy2HCzZ0 dqFb6T66IiYLwrOjJbib7OcejVWEZPXRB60otloBJqcXzsHs9TxAIdZmxIWGkA0TV3D9ErwWM Kcg7PyseFwadXAxidXngAYdifCq800H6O4643iU5mKVyZKp42DJ/IUj9trQcQ7ylp+X1lXX8n L44hwE1GrkxwQ4Iwj5fpRyC5LYu4aXDpLnVCr2Zoyw1+62au3y3ixaj/HX59pNieKDYwO1ZSM ok+aj5fPv5vQ9Oxs1ohNh0YahKFD4CKqkZWShV92SkwslhiBTqHnCerRM2Ct70NXle9dP96GC SLkKWba4TLliKdsXHO/RCQd95ZP2RDLvWK2uX/VTHZINiI4lUFFN+cgruV6W6M4UTVE3v54gg REqw97vi2lblAILjZ2xq+Jr7C1bSrDsTAQVXJze4hH+r4Fnmvvqvjwlv9mHm48izIgo8EYEI Received-SPF: pass client-ip=212.227.17.22; envelope-from=stephen.berman@gmx.net; helo=mout.gmx.net X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.93, RCVD_IN_SBL_CSS=3.335, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:148393 Archived-At: On Mon, 25 Nov 2024 16:36:46 +0000 Heime wrot= e: > Sent with Proton Mail secure email. > > On Tuesday, November 26th, 2024 at 2:58 AM, Stephen Berman > wrote: > >> On Mon, 25 Nov 2024 13:10:57 +0000 Heime heimeborgia@protonmail.com wro= te: >> >> > 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 f= or >> > > > > > > > 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 pr= obably 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 t= o >> > > evaluate the lambda expressions). I was just referring to the speci= fic >> > > function calls you used. >> > > >> > > > > > > What would you suggest for function commands requiring argu= ments, >> > > > > > > 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 wi= thin >> > > > > 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 o= f >> 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 wrot= e: > 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