all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Arbitrary function: find the number(s) of expected arguments
@ 2016-03-15 18:48 Paul Pogonyshev
  2016-03-15 22:45 ` Davis Herring
  2016-03-16  3:47 ` Stefan Monnier
  0 siblings, 2 replies; 60+ messages in thread
From: Paul Pogonyshev @ 2016-03-15 18:48 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1332 bytes --]

Hi,

Suppose I have a library with

    (defun my-foo (callback)
      ...
      (funcall callback computed-data))

Now, _some_ users of my library found out that it would be nice to have
`this-value-gets-computed-as-side-effect' too, though it is not really
necessary for callbacks in general. I wouldn't want to change interface of
the library, instead I would just improve it like this:

    (defun my-foo (callback)
      ...
      (if (accepts-2-arguments callback)
          (funcall callback computed-data
this-value-gets-computed-as-side-effect)
        (funcall callback computed-data)))

This way `my-foo' automagically accepts callbacks that expect one argument
(as in initial form), as well as those that want two arguments.

The problem, of course, is to write `accepts-2-arguments'.  I found
`subr-arity', which provides exactly what I need, but only for builtins...
I was also told about `help-function-arglist', but it returns the raw
argument list in which you still have to handle &optional or &rest (maybe
something else too?). This looks like a bit too much work for simple thing
and likely not good for performance-critical places either.

Feature request: add a builtin like `subr-arity' that works for _any_
function. Evaluator sure knows how to call the functions, so the
information is already there.

Paul

[-- Attachment #2: Type: text/html, Size: 1677 bytes --]

^ permalink raw reply	[flat|nested] 60+ messages in thread

end of thread, other threads:[~2016-04-18 23:02 UTC | newest]

Thread overview: 60+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-15 18:48 Arbitrary function: find the number(s) of expected arguments Paul Pogonyshev
2016-03-15 22:45 ` Davis Herring
2016-03-16  7:41   ` Paul Pogonyshev
2016-03-19 12:26     ` Paul Pogonyshev
2016-03-19 13:10       ` Eli Zaretskii
2016-03-19 13:42         ` Paul Pogonyshev
2016-03-19 13:54         ` Michael Heerdegen
2016-03-19 14:08           ` Eli Zaretskii
2016-03-19 15:20             ` Michael Heerdegen
2016-03-19 15:43               ` Eli Zaretskii
2016-03-19 15:57                 ` Michael Heerdegen
2016-03-19 16:24                   ` Eli Zaretskii
2016-03-19 17:43                     ` Michael Heerdegen
2016-03-19 17:50                       ` Eli Zaretskii
2016-03-19 17:59                         ` Michael Heerdegen
2016-03-19 18:14                           ` Eli Zaretskii
2016-03-19 16:14                 ` Philipp Stephani
2016-03-19 16:27                   ` Michael Heerdegen
2016-03-19 16:27                   ` Eli Zaretskii
2016-03-19 16:30                     ` Philipp Stephani
2016-03-19 16:32                       ` Eli Zaretskii
2016-03-19 16:34                         ` Philipp Stephani
2016-03-19 16:46                           ` Philipp Stephani
2016-03-19 16:47                           ` Eli Zaretskii
2016-03-19 17:16                             ` Philipp Stephani
2016-03-19 17:48                               ` Eli Zaretskii
2016-03-19 17:49                                 ` Philipp Stephani
2016-03-19 18:11                                   ` Eli Zaretskii
2016-03-19 18:35                                     ` Michael Heerdegen
2016-04-18 23:02                 ` Davis Herring
2016-03-19 19:52         ` Stefan Monnier
2016-03-19 20:33           ` Eli Zaretskii
2016-03-19 22:43             ` Stefan Monnier
2016-03-26 15:55           ` Elias Mårtenson
2016-03-26 17:20             ` Stefan Monnier
2016-03-19 14:26       ` Philipp Stephani
2016-03-19 16:51         ` Paul Pogonyshev
2016-03-19 18:09           ` Eli Zaretskii
2016-03-19 19:32             ` Michael Heerdegen
2016-03-19 19:39               ` Eli Zaretskii
2016-03-19 20:59                 ` Michael Heerdegen
2016-03-21 18:36             ` Paul Pogonyshev
2016-03-25  8:44               ` Eli Zaretskii
2016-03-25 16:16                 ` Paul Pogonyshev
2016-03-25 16:35                   ` Drew Adams
2016-03-25 17:16                     ` Paul Pogonyshev
2016-03-25 18:19                       ` Drew Adams
2016-03-25 18:28                         ` Clément Pit--Claudel
2016-03-25 18:51                           ` Use plain-text for mail [was: Arbitrary function: find the number(s) of expected arguments] Drew Adams
2016-03-25 18:57                             ` Use plain-text for mail [ Lars Magne Ingebrigtsen
2016-03-25 19:49                               ` Andreas Schwab
2016-03-26  1:12                             ` Use plain-text for mail [was: Arbitrary function: find the number(s) of expected arguments] Yuri Khan
2016-03-25 17:39                     ` Arbitrary function: find the number(s) of expected arguments Eli Zaretskii
2016-03-25 18:31                       ` Drew Adams
2016-03-26  8:27                   ` Eli Zaretskii
2016-03-26 11:42                     ` Paul Pogonyshev
2016-04-02  9:48                       ` Eli Zaretskii
     [not found]           ` <<83y49e731p.fsf@gnu.org>
2016-03-19 19:21             ` Drew Adams
2016-04-18 18:43               ` Davis Herring
2016-03-16  3:47 ` Stefan Monnier

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.