* Invoking a function from a list of functions
@ 2018-11-08 23:01 Tim Johnson
2018-11-09 1:25 ` Eric Abrahamsen
2018-11-09 8:58 ` Andreas Röhler
0 siblings, 2 replies; 14+ messages in thread
From: Tim Johnson @ 2018-11-08 23:01 UTC (permalink / raw)
To: Emacs
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
--
Tim Johnson
http://www.tj49.com
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Invoking a function from a list of functions
2018-11-08 23:01 Invoking a function from a list of functions Tim Johnson
@ 2018-11-09 1:25 ` Eric Abrahamsen
2018-11-09 6:03 ` Tim Johnson
[not found] ` <mailman.3694.1541743398.1284.help-gnu-emacs@gnu.org>
2018-11-09 8:58 ` Andreas Röhler
1 sibling, 2 replies; 14+ messages in thread
From: Eric Abrahamsen @ 2018-11-09 1:25 UTC (permalink / raw)
To: help-gnu-emacs
Tim Johnson <tim@akwebsoft.com> 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! :)
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Invoking a function from a list of functions
2018-11-09 1:25 ` Eric Abrahamsen
@ 2018-11-09 6:03 ` Tim Johnson
2018-11-09 10:30 ` Marcin Borkowski
` (2 more replies)
[not found] ` <mailman.3694.1541743398.1284.help-gnu-emacs@gnu.org>
1 sibling, 3 replies; 14+ messages in thread
From: Tim Johnson @ 2018-11-09 6:03 UTC (permalink / raw)
To: help-gnu-emacs
* Eric Abrahamsen <eric@ericabrahamsen.net> [181108 16:28]:
> Tim Johnson <tim@akwebsoft.com> 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
http://www.tj49.com
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Invoking a function from a list of functions
2018-11-09 6:03 ` Tim Johnson
@ 2018-11-09 10:30 ` Marcin Borkowski
2018-11-09 11:52 ` Noam Postavsky
2018-11-09 14:16 ` Yuri Khan
2 siblings, 0 replies; 14+ messages in thread
From: Marcin Borkowski @ 2018-11-09 10:30 UTC (permalink / raw)
To: Tim Johnson; +Cc: help-gnu-emacs
On 2018-11-09, at 07:03, Tim Johnson <tim@akwebsoft.com> wrote:
> * Eric Abrahamsen <eric@ericabrahamsen.net> [181108 16:28]:
>> Tim Johnson <tim@akwebsoft.com> 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.
Just guessing:
first-class functions/closures?
functions as data?
dynamic function calling?
Hth,
--
Marcin Borkowski
http://mbork.pl
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Invoking a function from a list of functions
2018-11-09 6:03 ` Tim Johnson
2018-11-09 10:30 ` Marcin Borkowski
@ 2018-11-09 11:52 ` Noam Postavsky
2018-11-09 13:12 ` Van L
2018-11-09 16:14 ` Tim Johnson
2018-11-09 14:16 ` Yuri Khan
2 siblings, 2 replies; 14+ messages in thread
From: Noam Postavsky @ 2018-11-09 11:52 UTC (permalink / raw)
To: Help Gnu Emacs mailing list
On Fri, 9 Nov 2018 at 01:03, Tim Johnson <tim@akwebsoft.com> wrote:
> 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.
> If I wished to further research this topic
What is "this topic"? Extracting a value from a list? Calling a function?
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Invoking a function from a list of functions
2018-11-09 6:03 ` Tim Johnson
2018-11-09 10:30 ` Marcin Borkowski
2018-11-09 11:52 ` Noam Postavsky
@ 2018-11-09 14:16 ` Yuri Khan
2018-11-09 16:22 ` Tim Johnson
2 siblings, 1 reply; 14+ messages in thread
From: Yuri Khan @ 2018-11-09 14:16 UTC (permalink / raw)
To: help-gnu-emacs
On Fri, Nov 9, 2018 at 1:03 PM Tim Johnson <tim@akwebsoft.com> 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)
> 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)
>
> If I wished to further research this topic using a search engine
> what are the keywords that I might feed to google?
The term you are looking for is “first-class functions”. This refers
to passing functions as arguments to other functions, returning
functions out of functions, storing functions in variables and data
structures, and otherwise treating functions the same way as other
values.
A related term, but from object-oriented programming, is “virtual
method”. This is a narrower concept, that you might want to call
different implementations of a function depending on the type of its
argument.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Invoking a function from a list of functions
2018-11-09 14:16 ` Yuri Khan
@ 2018-11-09 16:22 ` Tim Johnson
2018-11-09 16:37 ` Stefan Monnier
0 siblings, 1 reply; 14+ messages in thread
From: Tim Johnson @ 2018-11-09 16:22 UTC (permalink / raw)
To: help-gnu-emacs
* Yuri Khan <yurivkhan@gmail.com> [181109 05:28]:
> On Fri, Nov 9, 2018 at 1:03 PM Tim Johnson <tim@akwebsoft.com> 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)
>
> > 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)
> >
> > If I wished to further research this topic using a search engine
> > what are the keywords that I might feed to google?
>
> The term you are looking for is “first-class functions”. This refers
> to passing functions as arguments to other functions, returning
> functions out of functions, storing functions in variables and data
> structures, and otherwise treating functions the same way as other
> values.
That is exactly correct, yet I find nothing on this topic using
“first-class functions” as a keyword/phrase.
This obscurity is shared by python. The 'list-or-dictionary-of- functions
approach that I've used for years in python is just as
hard to search for. I believe I also used that tactic in C back
when I did GUI programming, but it has been so very long and I'm so
very retired ... :)
> A related term, but from object-oriented programming, is “virtual
> method”. This is a narrower concept, that you might want to call
> different implementations of a function depending on the type of its
> argument.
>
thanks
--
Tim Johnson
http://www.tj49.com
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Invoking a function from a list of functions
2018-11-09 16:22 ` Tim Johnson
@ 2018-11-09 16:37 ` Stefan Monnier
0 siblings, 0 replies; 14+ messages in thread
From: Stefan Monnier @ 2018-11-09 16:37 UTC (permalink / raw)
To: help-gnu-emacs
> That is exactly correct, yet I find nothing on this topic using
> “first-class functions” as a keyword/phrase.
I'm not sure exactly what kind of information you're looking for about
that, but maybe other related keywords might be "indirect function call"
(i.e. `funcall`) and "higher-order function" (which is the term used to
denote the functions that manipulate other functions, such as `mapcar`).
Stefan
^ permalink raw reply [flat|nested] 14+ messages in thread
[parent not found: <mailman.3694.1541743398.1284.help-gnu-emacs@gnu.org>]
* Re: Invoking a function from a list of functions
[not found] ` <mailman.3694.1541743398.1284.help-gnu-emacs@gnu.org>
@ 2018-11-09 7:09 ` Ihor Radchenko
0 siblings, 0 replies; 14+ messages in thread
From: Ihor Radchenko @ 2018-11-09 7:09 UTC (permalink / raw)
To: Tim Johnson, help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 3013 bytes --]
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))
#+end_src
You can also take a look at =dash.el=. There are many useful list
functions there.
Best,
Ihor
Tim Johnson <tim@akwebsoft.com> writes:
> * Eric Abrahamsen <eric@ericabrahamsen.net> [181108 16:28]:
>> Tim Johnson <tim@akwebsoft.com> 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
> http://www.tj49.com
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Invoking a function from a list of functions
2018-11-08 23:01 Invoking a function from a list of functions Tim Johnson
2018-11-09 1:25 ` Eric Abrahamsen
@ 2018-11-09 8:58 ` Andreas Röhler
2018-11-09 16:24 ` Tim Johnson
1 sibling, 1 reply; 14+ messages in thread
From: Andreas Röhler @ 2018-11-09 8:58 UTC (permalink / raw)
To: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Invoking a function from a list of functions
2018-11-09 8:58 ` Andreas Röhler
@ 2018-11-09 16:24 ` Tim Johnson
0 siblings, 0 replies; 14+ messages in thread
From: Tim Johnson @ 2018-11-09 16:24 UTC (permalink / raw)
To: help-gnu-emacs
* 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
^ permalink raw reply [flat|nested] 14+ messages in thread
[parent not found: <mailman.3677.1541718983.1284.help-gnu-emacs@gnu.org>]
end of thread, other threads:[~2018-11-12 5:39 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-11-08 23:01 Invoking a function from a list of functions Tim Johnson
2018-11-09 1:25 ` Eric Abrahamsen
2018-11-09 6:03 ` Tim Johnson
2018-11-09 10:30 ` Marcin Borkowski
2018-11-09 11:52 ` Noam Postavsky
2018-11-09 13:12 ` Van L
2018-11-09 16:14 ` Tim Johnson
2018-11-09 14:16 ` Yuri Khan
2018-11-09 16:22 ` Tim Johnson
2018-11-09 16:37 ` Stefan Monnier
[not found] ` <mailman.3694.1541743398.1284.help-gnu-emacs@gnu.org>
2018-11-09 7:09 ` Ihor Radchenko
2018-11-09 8:58 ` Andreas Röhler
2018-11-09 16:24 ` Tim Johnson
[not found] <mailman.3677.1541718983.1284.help-gnu-emacs@gnu.org>
2018-11-12 5:39 ` Rusi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).