[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
- Re: Invoking a function from a list of functions, (continued)
Message not available
Re: Invoking a function from a list of functions, Andreas Röhler, 2018/11/09
- Re: Invoking a function from a list of functions,
Tim Johnson <=
Re: Invoking a function from a list of functions, Rusi, 2018/11/12
- [OFFTOPIC] Re: Invoking a function from a list of functions, Stefan Monnier, 2018/11/12
- Message not available
- Re: [OFFTOPIC] Re: Invoking a function from a list of functions, Rusi, 2018/11/15
- Re: [OFFTOPIC] Re: Invoking a function from a list of functions, James K. Lowden, 2018/11/16
- Re: [OFFTOPIC] Re: Invoking a function from a list of functions, Rusi, 2018/11/17
- Re: [OFFTOPIC] Re: Invoking a function from a list of functions, James K. Lowden, 2018/11/19
- Re: [OFFTOPIC] Re: Invoking a function from a list of functions, Stefan Monnier, 2018/11/19
- Re: [OFFTOPIC] Re: Invoking a function from a list of functions, Amin Bandali, 2018/11/20
- Re: [OFFTOPIC] Re: Invoking a function from a list of functions, Stefan Monnier, 2018/11/21
- Re: [OFFTOPIC] Re: Invoking a function from a list of functions, Amin Bandali, 2018/11/22