From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: Arbitrary function: find the number(s) of expected arguments Date: Sat, 19 Mar 2016 17:43:38 +0200 Message-ID: <838u1e8od1.fsf@gnu.org> References: <56E8906C.5050405@lanl.gov> <83egb68vfy.fsf@gnu.org> <87zituefp9.fsf@web.de> <83a8lu8srs.fsf@gnu.org> <87twk2ebp2.fsf@web.de> Reply-To: Eli Zaretskii NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1458402262 16513 80.91.229.3 (19 Mar 2016 15:44:22 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 19 Mar 2016 15:44:22 +0000 (UTC) Cc: emacs-devel@gnu.org To: Michael Heerdegen Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Mar 19 16:44:17 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ahJ33-0005Zl-3C for ged-emacs-devel@m.gmane.org; Sat, 19 Mar 2016 16:44:17 +0100 Original-Received: from localhost ([::1]:49279 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ahJ32-00087H-KJ for ged-emacs-devel@m.gmane.org; Sat, 19 Mar 2016 11:44:16 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44893) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ahJ2w-000872-Q6 for emacs-devel@gnu.org; Sat, 19 Mar 2016 11:44:13 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ahJ2s-0004jh-It for emacs-devel@gnu.org; Sat, 19 Mar 2016 11:44:10 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:57789) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ahJ2s-0004jV-Ep; Sat, 19 Mar 2016 11:44:06 -0400 Original-Received: from 84.94.185.246.cable.012.net.il ([84.94.185.246]:3851 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1ahJ2r-00088y-H8; Sat, 19 Mar 2016 11:44:05 -0400 In-reply-to: <87twk2ebp2.fsf@web.de> (message from Michael Heerdegen on Sat, 19 Mar 2016 16:20:41 +0100) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:201868 Archived-At: > From: Michael Heerdegen > Cc: emacs-devel@gnu.org > Date: Sat, 19 Mar 2016 16:20:41 +0100 > > Eli Zaretskii 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. It will only do that if people don't quite understand what they are doing. I don't think we should assume our users will do that. > 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. But Emacs itself clearly _knows_ that only one argument is acceptable. So a function that replicates the steps made by the Lisp interpreter to arrive at this conclusion will be able to reach the same conclusion. So I don't see any insoluble problems here. > 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). I don't see how you reach this conclusion, except if you consider faulty implementations. > > > 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. When an advice has been installed, that is already known, isn't it? Once again, how does Emacs know? > > > 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. But it covers only a part of the turf. So nothing bad will happen if we enlarge the turf a bit, right? > 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). Triggering an exception only answers a yes/no question, which is not necessarily what is needed. It is also a terribly inelegant solution, IMO.