help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Invoking a function from a list of functions


From: Tim Johnson
Subject: Re: Invoking a function from a list of functions
Date: Fri, 9 Nov 2018 07:24:31 -0900
User-agent: Mutt/1.10.0 (2018-05-17)

* Andreas Röhler <andreas.roehler@easy-emacs.de> [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))
> > 
> > And assuming that these functions have a similar argument list,
> > I can invoke a function as:
> > 
> > (funcall (nth 1 funcs))
> > ;; or optionally
> > (funcall (nth 1 funcs) 2)
> > 
> > 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.
> > 
> > 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.
> > 
> > I had a heck of a time getting relevant responses from google. I
> > actually don't know what keywords to search with.
> > 
> > thanks
> > GNU Emacs 26.1 GTK+ Version, Ubuntu 16.04
> > 
> 
> 
> Maybe that way:
> 
> (defun foo ()
>   (message "%s" "foo"))
> 
> (defun bar ()
>   (message "%s" "bar"))
> 
> (setq my-list-of-functions (list 'foo 'bar))
> 
> (funcall (nth 1 my-list-of-functions))
> 
> ;;;;;
> 
> 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() 
  you get an address. Same with C/C++ - if I recall correctly.

-- 
Tim Johnson
http://www.tj49.com



reply via email to

[Prev in Thread] Current Thread [Next in Thread]