From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Heime via Users list for the GNU Emacs text editor Newsgroups: gmane.emacs.help Subject: Re: Making alist that executes multiple commands Date: Mon, 25 Nov 2024 16:36:46 +0000 Message-ID: References: <87wmgss0k6.fsf@gmx.net> <87sergrz2j.fsf@gmx.net> <87mshn8xd8.fsf@gmx.net> <87wmgr742q.fsf@rub.de> Reply-To: Heime Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28545"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Heime via Users list for the GNU Emacs text editor To: Stephen Berman Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Mon Nov 25 17:37:35 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 1tFc5f-0007EF-EW for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 25 Nov 2024 17:37:35 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tFc52-0004kM-Uu; Mon, 25 Nov 2024 11:36:56 -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 1tFc51-0004kE-J6 for help-gnu-emacs@gnu.org; Mon, 25 Nov 2024 11:36:55 -0500 Original-Received: from mail-4319.protonmail.ch ([185.70.43.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tFc4z-0005Qn-De for help-gnu-emacs@gnu.org; Mon, 25 Nov 2024 11:36:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1732552609; x=1732811809; bh=auvG7UpVD/8gQViuTqbJ9KlTYB6ZDpD48Yjno8yBgEI=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=gInEcWaIwEzZB27cnyWLqwu7PPCIUQ0k+GTkydXCAalO6iMH7c819H3/D5qusVv4N 7GdoWgfNNMZ83XblxcukAooXK6UtPEcrRcFnMi7Gcl4HSvboKdTxRA4n6U4aISEeBM eq+tFCIQD6W1mrUrPVvZUsun6CCNByP8jTPnMYPOIwpQGHCT0GEVHX6JBSOqxHNsOJ HA5QfEv/K20Oi9T590/NbT6se2TfcKVoNRHbDMJyz2gjmCxd0UJi+mG0rDsTkjoZRK sAwoL8DgoeyjkISSQTn82vmWztZlgiNzNxX9hd5lV4RHf1JOSB8Y4dptTX3OLGMd2p Y+ge4TdrczZYg== In-Reply-To: <87wmgr742q.fsf@rub.de> Feedback-ID: 57735886:user:proton X-Pm-Message-ID: 2ec5b4e145cdb76706d8ad2d4c3b81eff4f664c2 Received-SPF: pass client-ip=185.70.43.19; envelope-from=heimeborgia@protonmail.com; helo=mail-4319.protonmail.ch X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham 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:148391 Archived-At: 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 wrote= : >=20 > > Sent with Proton Mail secure email. > >=20 > > On Monday, November 25th, 2024 at 9:40 PM, Stephen Berman > > stephen.berman@gmx.net wrote: > >=20 > > > On Mon, 25 Nov 2024 01:05:10 +0000 Heime heimeborgia@protonmail.com w= rote: > > >=20 > > > > On Monday, November 25th, 2024 at 11:39 AM, Heime via Users list fo= r the GNU > > > > Emacs text editor help-gnu-emacs@gnu.org wrote: > > > >=20 > > > > > Sent with Proton Mail secure email. > > > > >=20 > > > > > On Monday, November 25th, 2024 at 11:28 AM, Stephen Berman > > > > > stephen.berman@gmx.net wrote: > > > > >=20 > > > > > > On Sun, 24 Nov 2024 23:13:51 +0000 Heime heimeborgia@protonmail= .com wrote: > > > > > >=20 > > > > > > > On Monday, November 25th, 2024 at 10:56 AM, Stephen Berman > > > > > > > stephen.berman@gmx.net wrote: > > > > > > >=20 > > > > > > > > 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: > > > > > > > >=20 > > > > > > > > > What changes can I make to the following to allow me to e= xecute more > > > > > > > > > commands than just one (as in alkotr-ar and alkotr-go). > > > > > > > > >=20 > > > > > > > > > For ar I want to call functions alkotr-ar and alkotr-af > > > > > > > > >=20 > > > > > > > > > (let ( (lookup-alist > > > > > > > > > '((ar . alkotr-ar) > > > > > > > > > (go . alkotr-go)))) > > > > > > > > >=20 > > > > > > > > > (dolist (actm symbol-list) > > > > > > > > > (let ((func (cdr (assoc actm lookup-alist)))) > > > > > > > > > (if func > > > > > > > > > (funcall func) > > > > > > > > > (message "ACTM Unrecognised: %s%s" "'" actm))))) > > > > > > > >=20 > > > > > > > > Something like this: > > > > > > > >=20 > > > > > > > > (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))))))) > > > > > > > >=20 > > > > > > > > Steve Berman > > > > > > >=20 > > > > > > > Have thought about this. Any criticisms about it? > > > > > > >=20 > > > > > > > '((ar . (lambda () > > > > > > > (alkotr-ar) > > > > > > > (alkotr-af))) > > > > > > >=20 > > > > > > > (go . (lambda () > > > > > > > (alkotr-go) > > > > > > > (alkotr-gc)))) > > > > > >=20 > > > > > > That seems fine if the functions take no arguments, though prob= ably not > > > > > > as flexible as looping over a list. > > > > >=20 > > > > > Could you explain? Can't I do > > > > >=20 > > > > > (go . (lambda () > > > > > (alkotr-go go) > > > > > (alkotr-gc gc)) > > >=20 > > > Yes (but as Stefan Monnier pointed out and I overlooked, you have to > > > evaluate the lambda expressions). I was just referring to the specifi= c > > > function calls you used. > > >=20 > > > > > > > What would you suggest for function commands requiring argume= nts, > > > > > > > e.g. (alkotr-ar ar) and (alkotr-af af)? > > > > > >=20 > > > > > > (funcall 'alkotr-ar ar) > > > > > > (funcall 'alkotr-ar af) > > > > >=20 > > > > > How would the above solution fit with argument incorporation with= in > > > > > lookup-alist? > > >=20 > > > I'm not sure what you're asking here. > > >=20 > > > > Does one use > > > >=20 > > > > (lookup-alist '( (ar (alkotr-ar arg-ar) (alkotr-af arg-af)) > > > > (go (alkotr-go arg-go) (alkotr-gc arg-gc))) )) > > >=20 > > > Use it for what? > > >=20 > > > Steve Berman > >=20 > > (defun fpln-test (symbol-list) >=20 > ^^^^^^^^^^^ >=20 > > (let ((symbol-list '(ar go)) >=20 > ^^^^^^^^^^^^^^^^^^^^^^ >=20 > 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. =20 > > (lookup-alist '((ar alkotr-ar alkotr-af) > > (go alkotr-go alkotr-gc)))) > >=20 > > (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)))))))) > >=20 > > You suggested the use use of > >=20 > > (funcall 'alkotr-ar ar) > > (funcall 'alkotr-ar af) > >=20 > > Where are they to be introduced? > >=20 > > 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. >=20 >=20 > 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. >=20 > 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=20 suggest. =20 (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))))))