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 20:09:22 +0200 Message-ID: <83y49e731p.fsf@gnu.org> References: <56E8906C.5050405@lanl.gov> Reply-To: Eli Zaretskii NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1458411019 18072 80.91.229.3 (19 Mar 2016 18:10:19 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 19 Mar 2016 18:10:19 +0000 (UTC) Cc: emacs-devel@gnu.org To: Paul Pogonyshev Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Mar 19 19:10:16 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 1ahLKI-0002l4-6T for ged-emacs-devel@m.gmane.org; Sat, 19 Mar 2016 19:10:14 +0100 Original-Received: from localhost ([::1]:49944 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ahLKH-0004fU-EG for ged-emacs-devel@m.gmane.org; Sat, 19 Mar 2016 14:10:13 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50475) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ahLK0-0004c8-Pc for emacs-devel@gnu.org; Sat, 19 Mar 2016 14:09:58 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ahLJv-0001en-QB for emacs-devel@gnu.org; Sat, 19 Mar 2016 14:09:56 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:33082) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ahLJv-0001eh-MH; Sat, 19 Mar 2016 14:09:51 -0400 Original-Received: from 84.94.185.246.cable.012.net.il ([84.94.185.246]:4399 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1ahLJu-0006Tj-R1; Sat, 19 Mar 2016 14:09:51 -0400 In-reply-to: (message from Paul Pogonyshev on Sat, 19 Mar 2016 17:51:39 +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:201891 Archived-At: > Date: Sat, 19 Mar 2016 17:51:39 +0100 > From: Paul Pogonyshev > Cc: emacs-devel@gnu.org > > Approximate patch, without documentation. If this is accepted, I can write documentation too. I submitted > legal papers for FSF years ago. Thanks. A few comments below. Let's wait for a few days to give others a chance to comment. > (func-arity 'car) (1 . 1) > (func-arity 'caar) (1 . 1) > (func-arity 'magit-log-all) (0 . 2) > (func-arity 'format) (1 . many) > (func-arity (lambda (&rest x))) (0 . many) How about adding a few tests for this in test/ ? > +Lisp_Object > +get_byte_code_arity (Lisp_Object args_template) > +{ > + if (INTEGERP (args_template)) > + { > + ptrdiff_t at = XINT (args_template); > + bool rest = (at & 128) != 0; > + int mandatory = at & 127; > + ptrdiff_t nonrest = at >> 8; > + > + return Fcons (make_number (mandatory), rest ? Qmany : make_number (nonrest)); > + } > + else > + error ("Unknown args template!"); It could also be a list (that was the old style). Maybe we should also support that, in case some old byte-compiled file is used? I think you already have the necessary code in lambda_arity. > + if (SUBRP (function)) > + { > + minargs = XSUBR (function)->min_args; > + maxargs = XSUBR (function)->max_args; > + result = Fcons (make_number (minargs), > + maxargs == MANY ? Qmany > + : maxargs == UNEVALLED ? Qunevalled > + : make_number (maxargs)); > + } We have sub-arity, so I think we should remove it and leave an alias that will call this new function for backward compatibility. Having both sounds redundant.