From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Michael Heerdegen Newsgroups: gmane.emacs.devel Subject: Re: Arbitrary function: find the number(s) of expected arguments Date: Sat, 19 Mar 2016 16:20:41 +0100 Message-ID: <87twk2ebp2.fsf@web.de> References: <56E8906C.5050405@lanl.gov> <83egb68vfy.fsf@gnu.org> <87zituefp9.fsf@web.de> <83a8lu8srs.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1458400877 28637 80.91.229.3 (19 Mar 2016 15:21:17 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 19 Mar 2016 15:21:17 +0000 (UTC) Cc: emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Mar 19 16:21:08 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 1ahIge-0008En-4e for ged-emacs-devel@m.gmane.org; Sat, 19 Mar 2016 16:21:08 +0100 Original-Received: from localhost ([::1]:49202 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ahIgd-0006xG-7K for ged-emacs-devel@m.gmane.org; Sat, 19 Mar 2016 11:21:07 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38963) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ahIgN-0006wI-Mg for emacs-devel@gnu.org; Sat, 19 Mar 2016 11:20:52 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ahIgM-0006o0-Li for emacs-devel@gnu.org; Sat, 19 Mar 2016 11:20:51 -0400 Original-Received: from mout.web.de ([212.227.15.4]:64816) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ahIgI-0006nl-GJ; Sat, 19 Mar 2016 11:20:46 -0400 Original-Received: from drachen.dragon ([94.218.210.27]) by smtp.web.de (mrweb004) with ESMTPSA (Nemesis) id 0MHdwC-1adzIF2sY8-003KT1; Sat, 19 Mar 2016 16:20:43 +0100 In-Reply-To: <83a8lu8srs.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 19 Mar 2016 16:08:23 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.92 (gnu/linux) X-Provags-ID: V03:K0:sdWi+ki7LrpBpJXFgZBFfCl7eJQmBOf2Mb2VMy7MjSQ67AnhffA cXWkSIrFmnERGuu2tS3CSItofynw7xsxsZUTOVTd1xQGHt2w/MSGz8lOoHq4LyxSnjP6byV tYw+j0ncfocsFZZ2fQYENBbF3I8hwQfsEA2nKUw69A7Ozrc9xlWvRcKPEOzYaNHH4winOUU kzEN8QwUZUwoZ7qBZ4pnQ== X-UI-Out-Filterresults: notjunk:1;V01:K0:kM1ZPkuEWug=:AoQ2ZMcUcM+NLrJ7a03pgD 3WoOvPTSpVaGqnw2+Yr0AynU4Nu5rZy6VDVA14zfCl3XQE5WefxYja8YKS2v3e7aRjUfpGX7B BlZPozDI39kL4SNG7mkSnp0W9H8y+gDXHqPEBH4z5/lXpicPzx51yVpfQy0kJTjQjM1N3aHzW dk9u8rnJ12UP8EFS5KFdm+R+35+CY18KrZPV27mV3G7N+Gi71mNAiC95X7E+fegwcZ/WlYtWb Xk1Y5Gb5VuBaaN2iUilYMrn4klnXDTBeXDrhqe/ryuO1zX3EGl21YUsAtO4NOPM4Muv1mHCOZ GB80LZzMzOKCJW4T0B/xMwiScZ4xCG3w6vz09DM2JRS1lZHjxQTPPpJ8NYBsfS9sB+zi1ctHg 98+R2ZQ0cyr5UXM+89v18CiQh4okFToLqmauFLJO8PIA3P+PSVB1DxzWokzHV/u2YbG3HI2/3 gvUZVjDI89cUhi/oGDYpuhkK1UHcpucxpJg3Pk6ZxGctn6VCHPrXXTN21w+yLrIJ/J9P9L9HE BgxvOXLYV6bTi+bfr1CtOU3ZQUIvMIuTLhJlaXiCRRMhUHNSBs0iyuzKj2ZnA48fehTJpvVaw ptcTiCHZutKbXOhzsk030nGGdhAhSSJiXggVSDPtp2Fm1e8FORhfeRhixP3Vl+mMDJ3vRiGwT 6TJ1ikZLKXxlZICnyXEw16+8cAbRLeQwvRmhpYfAVxrP/msSNOaKzp/L0s6fbU9xIz/NSWImH OS5F4UBaNgOAx5oYDUmqZryZiY909nm+g8zvt+550W32vPCl4fRhwrk2kQp8LS0qAnxtaWoO X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.15.4 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:201867 Archived-At: 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. 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.