all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Michael Heerdegen <michael_heerdegen@web.de>
To: Eli Zaretskii <eliz@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: Arbitrary function: find the number(s) of expected arguments
Date: Sat, 19 Mar 2016 16:20:41 +0100	[thread overview]
Message-ID: <87twk2ebp2.fsf@web.de> (raw)
In-Reply-To: <83a8lu8srs.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 19 Mar 2016 16:08:23 +0200")

Eli Zaretskii <eliz@gnu.org> writes:

> Do you have a better solution to suggest?  If so, let's hear it.

Not really.  The better solution would be that people should try to
avoid that situation.  This is not always possible, yes, but introducing
`fun-arity' would give a false appearance semblance reliability.

For example:

> > (defun f (a b) (list a b))
> > 
> > (defalias 'g (apply-partially #'f 1))
> > 
> > what would (func-arity 'g) return?
>
> Ideally, it should return (1 . 1).

This signature can be interpreted as "accepts any number of arguments",
whereby it doesn't.  The condition-case solution with the wrong number
of args handler at least also catches this case.

The problem with `func-arity' is that, as in the above example, can
return something that doesn't answer the question we talk about: "can
this function be called with these number of elements (e.g.)".  So it
only solves your problem if you are lucky (lucky at runtime).

> > What would it return for adviced functions?  An advice can change the
> > arity of a function.  Most do not, but most advices have an &rest args
> > signature.  Any function can be adviced.
>
> If the solution handles this complication, then it will return an
> accurate result.  If not, it will be a known limitation.

That's the problem: we can't handle this generally, since it can't be
known if and how an arbitrary advice calls the original funciton.

So after calling `func-arity' you still can't be sure whether a call
with a certain number of args or not.  That's not helpful.

> > My question is if it is a good idea to invite users to rely on
> > something like `func-arity'.
>
> You could ask the same about subr-arity, couldn't you?  And yet we do
> have it.

A subr is constant.  If you wrap it into another function, the result is
not a subr anymore.  So the result is at least more meaningful.


Hmm, A bit more reliable maybe (didn't think about it) would be
something semantically similar to

(condition-case nil
  (funcall function arguments ....)

 (wrong-number-of-arguments alternative-code ...))

that would catch "wrong-number-of-arguments" only at "top level" (which
would include calling the original function when FUNCTION is adviced,
but not function calls in the body of FUNCTION).


Michael.



  reply	other threads:[~2016-03-19 15:20 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87twk2ebp2.fsf@web.de \
    --to=michael_heerdegen@web.de \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.