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 21:18:28 +0000 Message-ID: References: <87mshn8xd8.fsf@gmx.net> <87wmgr742q.fsf@rub.de> <87jzcr6ooe.fsf@rub.de> <87frnf6n2l.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="10288"; 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 22:19:21 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 1tFgUL-0002Vd-BQ for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 25 Nov 2024 22:19:21 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tFgTg-0003iy-0k; Mon, 25 Nov 2024 16:18:40 -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 1tFgTd-0003ih-0j for help-gnu-emacs@gnu.org; Mon, 25 Nov 2024 16:18:37 -0500 Original-Received: from mail-43167.protonmail.ch ([185.70.43.167]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tFgTb-0000hG-1H for help-gnu-emacs@gnu.org; Mon, 25 Nov 2024 16:18:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1732569511; x=1732828711; bh=yd33VAqLWk5sXfC4QyWfLtN67wZOu/b1s/naIzki1JA=; 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=gAVT31BWXwQd0qatH0kxAIV4e8ZeLmdF1UVkJta3a4mvJTKLr249hdOFJCbLkC9eT KItuGdJxllBD0uMQWRDXwtw+bPa1E9UBszJrT2oOkWF7f7WVtr7yHOCN+I8OSh7llF H/kgUBakxVnlMF2ZkL7/0D4mYbpwvp6v8krhEK2EKmIYM8hYU+emTGJiwqAEqErHvL lE22deAGh9rGZEs4zGhjfXojjltY+nG7oM9JBUvHrdwnQw160Yl2DH/gSQArvqg1GH 6SDkJGKgGUwt9IiIueR/ZttnE74IEwNTvfkx3h3yUSJY7LR0LTVTdjlBWfwhVvYuGJ yGkd4Nmykpk+Q== In-Reply-To: <87frnf6n2l.fsf@rub.de> Feedback-ID: 57735886:user:proton X-Pm-Message-ID: 9980f7095804d52b43ff364e29934aa77483ae95 Received-SPF: pass client-ip=185.70.43.167; envelope-from=heimeborgia@protonmail.com; helo=mail-43167.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:148397 Archived-At: Sent with Proton Mail secure email. On Tuesday, November 26th, 2024 at 9:05 AM, Stephen Berman wrote: > On Mon, 25 Nov 2024 20:45:22 +0000 Heime heimeborgia@protonmail.com wrote= : >=20 > > > > 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? > > >=20 > > > Something like this, for example: > > >=20 > > > (dolist (f '(+ - list)) > > > (dolist (a '(1 2 3)) > > > (funcall f a))) > > >=20 > > > > I could have the following, but got some difficulties about > > > > how to execute each command with its arguments, in the way you > > > > 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))) )) ) > > > >=20 > > > > (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)))))) > > >=20 > > > When I wrote "using a list of function calls as the value of each ali= st > > > 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 wh= ose > > > first element is a function) is not a function. > >=20 > > 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. >=20 >=20 > 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=20 extensibility. Perhaps contrary to your original point of view?=20 Because I do not have to use explicit command lists. Lambdas also=20 allow dynamic and conditional logic. =20 > > > On Mon, 25 Nov 2024 17:59:22 +0000 Heime heimeborgia@protonmail.com w= rote: > > >=20 > > > > I get error when calling (marnap '(armg go)) > > > >=20 > > > > That is I get message "ACTM Unrecognised: 'armg" > > > >=20 > > > > (defun marnap (&optional actm-service) > > > >=20 > > > > (let ( (lookup-alist '((armg ((add-to-list 'load-path > > > > (marnap-sec-fpln-waypt "NAPLN")) > > > > (require 'napyon))) > > > >=20 > > > > (go ((napyon 'go))) )) ) > > > >=20 > > > > (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)))))) )) > > >=20 > > > This is for the same reason as above: the first invocation of `(car c= md)' returns` (add-to-list 'load-path (marnap-sec-fpln-waypt > > > "NAPLN"))', which is a function call, not a function. > > >=20 > > > Steve Berman > >=20 > > Have put another question to not complicate this discussion. > > Would it make sense to execute the function calls with eval. > >=20 > > Still that is also giving me problems with > >=20 > > (invalid-function (add-to-list 'load-path (marnap-sec-fpln-waypt "NAPLN= "))) >=20 >=20 > This is probably because you have something like this: >=20 > (eval ((add-to-list 'load-path (marnap-sec-fpln-waypt "NAPLN")) ...)) >=20 > 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. >=20 > Steve Berman