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 15:58:37 +0100 Message-ID: <87wmgr742q.fsf@rub.de> References: <87wmgss0k6.fsf@gmx.net> <87sergrz2j.fsf@gmx.net> <87mshn8xd8.fsf@gmx.net> 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="21217"; 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 15:59:24 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 1tFaYd-0005Kr-3g for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 25 Nov 2024 15:59:23 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tFaY3-000626-3P; Mon, 25 Nov 2024 09:58:47 -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 1tFaY1-00061C-P9 for help-gnu-emacs@gnu.org; Mon, 25 Nov 2024 09:58:45 -0500 Original-Received: from mout.gmx.net ([212.227.15.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tFaXz-0005qQ-Oj for help-gnu-emacs@gnu.org; Mon, 25 Nov 2024 09:58:45 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1732546719; x=1733151519; i=stephen.berman@gmx.net; bh=5seAVMNXB/KGAT8Tsy7AzwBbpb2nnr5ktl032BURJwY=; 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=RO8ABPN3BtxgnoDiDJunzui1AJQVg3riW8jEbMTM/FkxOEbOFLQPOWO/ZQNktbvT reScklMMwa6lBoMF9aRctM9EbNo9bCWhVMyDoTTDvGzTIBcyi9v9ulqim5sC+N1ky r2OmMt9tPR+erCTGtJqj92nwnyh503by6kQsJ/i1AtZmo/zwv4Kt7EuRuERAcO6x1 hBERw6HuzPH6zSXojIhuSJ1HgcjIJWsvidJlWlNjPHmw7cTiFk3QsjvZKyE1I9vWg OK0pxKudlGZ9wVHtHnlF+SZdCKbI14h0ESYr3xT4v11kT5ZaTYcDuex93l7xHm/R2 GlBbirGnFp1YkteALQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Original-Received: from strobelfssd ([88.130.50.169]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1McH9i-1tplEw46hg-00qG7L; Mon, 25 Nov 2024 15:58:39 +0100 In-Reply-To: (Heime's message of "Mon, 25 Nov 2024 13:10:57 +0000") X-Provags-ID: V03:K1:DVgpT/kdbgjXdLnV9rJ+jF8YX5usNJ+5boR3D61DMBWK4LpbWKB u/3eWT+vhn9qZZvyDb1KhFGiz+NaPIKFYLsF0sLuYWArxQmuIA6TtZWkS5wgeKK/Npr5pmH pb1BTM2YQvBWRGOhgxufAOavTWidlKeLZbVDhvcI11QEHLJ3sWhg2K2HITpnEe9pmriwa71 rRKNPsipe+CQ4mgjXmwKA== UI-OutboundReport: notjunk:1;M01:P0:gQA7YNfdYIg=;B1Gzm+2wIQB062TdmXKWrRzyKj3 Ee9QTxS4KHk3RWNZK4jmRtAtxZyUVCbByruWo6uCOVHWFxMbqCxvLlq6otudg/aRxRzwsfGnu 25Pg4eCyMLoGP5767ntH/QbSpfNrPPO+qXvH7+wGCVS7WLmnzLYz9tyKjm7X/CF3ZzdRBk0XK l8x7LjWKFuUm/qwuzRxltY817siXtsbV7x/WkHupbKGf//Fcr2ELah6avR0PMEd/7ovuZF98c z4Hb0Ovsqpcmyj22nBALtfPyartdHGo6zcPt/FFhrhkiNDIn8l6Yv7B3Khb+bh5oDVaN3ScN1 +NhLJGu4hsf+gCiIMIl8p/EohmoyozuPWgozUUblH9YZdY48VYw5iTYwYCRxcKTBE4Dc9HMIU tLQhuE47jH2irhV4U5ARoe3k0ZHn0xQgGqZOZcv1m+BXP4MwJv8vOpqxhOzPmSFO6wO82MjFh QF4ql14+usq1Vf+CO+5/urUwdx74TjBmK+8teVLW7Og2oGq8AkP24fCggeBijdJAuO8R8miuR b23+2x5mp/zOjFceVFWJHZPZNHAjV8zqUNWNRUYD6wtwKfu1vfM5ROa0lk6x23qbDD2MQf359 EfWfR1KxJ+pHX9zG8sG9x9LZqh22dCb7gJAKMvBKSIDwSnHCoRwLUVu97nfBrXf0tWsqLJrdO gm1KahdRTLUCgT+ykggvqQZmsS6j7P79MBTU3QQS0MjHrcHC+BxSG3OpHrO/fAe6sj2pEKCMN B2q3MlHFLsNsu9YsSG419DgW0V6TO+2SP0F4yDaKffCJ4zwxZC4xujQBjJjrZxF2GdKe36fY Received-SPF: pass client-ip=212.227.15.18; envelope-from=stephen.berman@gmx.net; helo=mout.gmx.net X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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:148390 Archived-At: On Mon, 25 Nov 2024 13:10:57 +0000 Heime wrot= e: > Sent with Proton Mail secure email. > > On Monday, November 25th, 2024 at 9:40 PM, Stephen Berman > wrote: > >> On Mon, 25 Nov 2024 01:05:10 +0000 Heime heimeborgia@protonmail.com wro= te: >> >> > 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.c= om 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 t= he GNU Emacs >> > > > > > text editor help-gnu-emacs@gnu.org wrote: >> > > > > > >> > > > > > > What changes can I make to the following to allow me to exe= cute 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 probab= ly 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 argument= s, >> > > > > 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