From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tim Johnson Newsgroups: gmane.emacs.help Subject: Re: Invoking a function from a list of functions Date: Fri, 9 Nov 2018 07:24:31 -0900 Organization: AkWebsoft Message-ID: <20181109162430.GE2179@mail.akwebsoft.com> References: <20181108230125.GA2179@mail.akwebsoft.com> <42ac8b40-7d1e-b578-f7e3-bbadefad62ea@easy-emacs.de> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1541780595 11266 195.159.176.226 (9 Nov 2018 16:23:15 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 9 Nov 2018 16:23:15 +0000 (UTC) User-Agent: Mutt/1.10.0 (2018-05-17) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Nov 09 17:23:11 2018 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gL9Yt-0002o6-Mq for geh-help-gnu-emacs@m.gmane.org; Fri, 09 Nov 2018 17:23:11 +0100 Original-Received: from localhost ([::1]:34950 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gL9b0-0007VW-5k for geh-help-gnu-emacs@m.gmane.org; Fri, 09 Nov 2018 11:25:22 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35713) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gL9aW-0007Lp-Kk for help-gnu-emacs@gnu.org; Fri, 09 Nov 2018 11:24:53 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gL9aS-0003uD-67 for help-gnu-emacs@gnu.org; Fri, 09 Nov 2018 11:24:52 -0500 Original-Received: from tjohnson.mtaonline.net ([64.4.232.191]:49310) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gL9aR-0003Lk-Or for help-gnu-emacs@gnu.org; Fri, 09 Nov 2018 11:24:48 -0500 Original-Received: by linus (Postfix, from userid 1000) id 07FDB240436; Fri, 9 Nov 2018 07:24:31 -0900 (AKST) Mail-Followup-To: help-gnu-emacs@gnu.org Content-Disposition: inline In-Reply-To: <42ac8b40-7d1e-b578-f7e3-bbadefad62ea@easy-emacs.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 64.4.232.191 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 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.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:118626 Archived-At: * Andreas R=F6hler [181109 00:02]: > On 09.11.2018 00:01, Tim Johnson wrote: > > Given a list of functions: > > (setq funcs '(scroll-up-line scroll-down-line)) > >=20 > > And assuming that these functions have a similar argument list, > > I can invoke a function as: > >=20 > > (funcall (nth 1 funcs)) > > ;; or optionally > > (funcall (nth 1 funcs) 2) > >=20 > > That approach is sufficient for my needs at the moment, an example > > of which might be to cycle through color themes invoked by my own > > functions. > >=20 > > However, in the quest for futher edification I'd welcome URLs to > > documentation or discussion, as well as any contributions other > > emacsen might choose to make. Keywords also. > >=20 > > I had a heck of a time getting relevant responses from google. I > > actually don't know what keywords to search with. > >=20 > > thanks > > GNU Emacs 26.1 GTK+ Version, Ubuntu 16.04 > >=20 >=20 >=20 > Maybe that way: >=20 > (defun foo () > (message "%s" "foo")) >=20 > (defun bar () > (message "%s" "bar")) >=20 > (setq my-list-of-functions (list 'foo 'bar)) >=20 > (funcall (nth 1 my-list-of-functions)) >=20 > ;;;;; >=20 > The point is to hand over functions as symbols, not their value And in Python, if you evaluate a function without the succeeding parens: foo vs. foo()=20 you get an address. Same with C/C++ - if I recall correctly. --=20 Tim Johnson http://www.tj49.com