[Top][All Lists]

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

Re: Invoking a function from a list of functions

From: Ihor Radchenko
Subject: Re: Invoking a function from a list of functions
Date: Fri, 09 Nov 2018 15:09:00 +0800

All the strength of `mapc`, `mapcar`, `reduce` and other list functions
is in your hands.

For example,
#+begin_src emacs-slip
(setq funclist (mapcar #'symbol-function '(forward-line forward-char)))
(mapc #'funcall funclist)
(cl-mapc #'funcall funclist (make-list (length funclist) 2))

You can also take a look at =dash.el=. There are many useful list
functions there.


Tim Johnson <> writes:

> * Eric Abrahamsen <> [181108 16:28]:
>> Tim Johnson <> writes:
>> > 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. 
>> It isn't clear to me, at least, what else you might be trying to achieve
>> here. Is it more accurately selecting a function from within a list,
>> using a keyword? Or cycling through functions in a list?
>> You'll have a heck of a time getting relevant responses on this list,
>> too, unless you tell us what you're after! :)
>   Thanks for the reply Eric: As I demonstrated on my code examples,
>   I know how to extract a function from a list and invoke it.
>   ... So that's done. Now, iterating thru a list of functions that
>   might invoke a particular color theme is an example of such an
>   application and I think I grok that.
>   What I am interested in is further discussion whether it be from
>   replies to this topic or more general topics in this area. I'm
>   restating that I've had a difficult time finding results from
>   google. 
>     --------------------------------------------------------
>     That is probably because I don't know the right keywords
>     or domain-specific terms to use
>     --------------------------------------------------------
>   This isn't just difficult for emacs/elisp, I've found it difficult
>   for python functions invoked from lists or dictionaries. (altho
>   I've employed such methods for years in python)
>   So I'm sorry to be so unclear: let me restate the nut and kernel
>   of my question: 
>   If I wished to further research this topic using a search engine
>   what are the keywords that I might feed to google?
>   I hope that you now understand what I'm after.
>   cheers
> -- 
> Tim Johnson

Attachment: signature.asc
Description: PGP signature

reply via email to

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