From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Paul Pogonyshev Newsgroups: gmane.emacs.devel Subject: Re: Arbitrary function: find the number(s) of expected arguments Date: Sat, 26 Mar 2016 12:42:17 +0100 Message-ID: References: <56E8906C.5050405@lanl.gov> <83y49e731p.fsf@gnu.org> <83pouj0wx8.fsf@gnu.org> <83zitlzlsj.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a11c2d0dae89a83052ef22b7b X-Trace: ger.gmane.org 1458992555 25921 80.91.229.3 (26 Mar 2016 11:42:35 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 26 Mar 2016 11:42:35 +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 26 12:42:34 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 1ajmby-0004Cm-8X for ged-emacs-devel@m.gmane.org; Sat, 26 Mar 2016 12:42:34 +0100 Original-Received: from localhost ([::1]:59758 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ajmbx-0003hO-Cv for ged-emacs-devel@m.gmane.org; Sat, 26 Mar 2016 07:42:33 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46916) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ajmbj-0003hH-9B for emacs-devel@gnu.org; Sat, 26 Mar 2016 07:42:20 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ajmbi-0001GW-2l for emacs-devel@gnu.org; Sat, 26 Mar 2016 07:42:19 -0400 Original-Received: from mail-ob0-x236.google.com ([2607:f8b0:4003:c01::236]:34811) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ajmbh-0001GO-SX; Sat, 26 Mar 2016 07:42:18 -0400 Original-Received: by mail-ob0-x236.google.com with SMTP id kf9so66693470obc.1; Sat, 26 Mar 2016 04:42:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc; bh=6HkBQUQ9nyY5P7C+0O6zq+HPz2I6MNY1VQKN0klwwhc=; b=G01TAPogCkHRDA42PrRLcSibUn5Ga/Gkp4lHN1y9eN31xSy0jvd+4wQ2ts0/R2FFhV NMj05+0aSYLYni+iprUf6PicVFifBcRHWoU1fkXBHUkpY0qYjHyC5k/GbBpG7mF41qdx DJinGnhqYh5W1e4rvKgoozOBXQEWxNelZmDWPzl2P/YHDwWi0Yj5/dzWlKQgPf9wuK+H Un00+U0MJ19/44r8pzBRHFp3WGld9SvFAhR+16nC/jGL9us6c/tCFTHjr+59yZk4cko5 6sawghGYs1t2faMO5OuN0/a3ad4UIyhq7bJvX4hXL77pwOAs/k2exr8qrKkScLhkYcCa IATg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc; bh=6HkBQUQ9nyY5P7C+0O6zq+HPz2I6MNY1VQKN0klwwhc=; b=VPxa1ofX3MNQ0bT5XqJyxZQp9b64T0YG7P/YbVCAkNtZ/zTpdHuKkXcaslHrF3TsPn XL0y/jivhzmeyMwV4VDuZPrGizKgpOG6V4BoxYSkpjY3JkidCNunCpH+36orXZTciQLm kjAF1dtPgQham26Ooz6oyzec6DbKWvcvZjvWVGPNL8j5TcEg5OgMZkPJtFiPHkRwPTYU /NJGbU+hLcTSvd2unAJGk1cmBi1LJftbyeDnUp9NHPMlcm2ytJ3f2ET01uFpK9iJ3FFW A8vCDa2YtqkvtcOxYqLOwK9wd6rIKo2TkHauHsQFaMJRVPUdmN5iJgY8+jZcty0J5c5L xNJg== X-Gm-Message-State: AD7BkJIxJUyPBXIt8yLNn2KTuSCZRoFjQM1I4i9Dn7tEb3nwi5krOEhPY95qXXx/FwqDceHqBWtQZExaRpo7FQ== X-Received: by 10.182.142.103 with SMTP id rv7mr5812037obb.40.1458992537178; Sat, 26 Mar 2016 04:42:17 -0700 (PDT) Original-Received: by 10.202.197.148 with HTTP; Sat, 26 Mar 2016 04:42:17 -0700 (PDT) In-Reply-To: <83zitlzlsj.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4003:c01::236 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:202254 Archived-At: --001a11c2d0dae89a83052ef22b7b Content-Type: text/plain; charset=UTF-8 Eli Zaretskii wrote: > > In the attached patch I modified `doc/lispref/functions.texi': text about > > `subr-arity' is moved to a new section above about `func-arity' and > > adapted as needed. `subr-arity' is still in the documentation, but I > > replaced its description with an advice to use `func-arity' instead. Is > > that enough? > > It's enough, but in the future please also provide a NEWS entry, like > the one I added. > > > Do you still need changelog entries? Long time since I committed > > anything to Emacs, maybe you finally got rid of them (I hope)? > > We no longer maintain ChangeLog files in the repository, but we do > request commit log messages in the ChangeLog format, so please do > provide them in the future. (I wrote them for you this time.) OK. > I pushed the changes to the master branch, thanks. Thank you. > There's one potential issue left: > > (func-arity 'with-temp-buffer) => error-> Invalid function: with-temp-buffer > > Is it possible to support macros as well? If not, how about producing > a more meaningful error message? Well, according to `functionp' macros are not functions, so it's sort of correct. On the other hand, it seems (symbol-function ...) works, returning ('macro . FUNCTION) for them. However, I can't find any real C-level way to handle macros, e.g. `macrop' is even not a builtin. Or is just treating them as lists fine? If so, we could add something like this (untested): diff --git a/src/eval.c b/src/eval.c index 64a6655..5c594b8 100644 --- a/src/eval.c +++ b/src/eval.c @@ -2958,6 +2958,9 @@ function with `&rest' args, or `unevalled' for a special form. */) && (function = XSYMBOL (function)->function, SYMBOLP (function))) function = indirect_function (function); + if (CONSP (function) && EQ (XCAR (function), Qmacro)) + function = XCDR (function); + if (SUBRP (function)) result = Fsubr_arity (function); else if (COMPILEDP (function)) However, I'm not exactly sure what will happen with autoloaded macros. Paul --001a11c2d0dae89a83052ef22b7b Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Eli Zaretskii wrote:
=
> > In the attached patch I modified `doc/lispref/functions.texi= ': text about
> > `subr-arity' is moved to a new se= ction above about `func-arity' and
> > adapted as neede= d. `subr-arity' is still in the documentation, but I
> >= ; replaced its description with an advice to use `func-arity' instead. = Is
> > that enough?
>=C2=A0
> It&= #39;s enough, but in the future please also provide a NEWS entry, like
> the one I added.
>
> > Do you still= need changelog entries? Long time since I committed
> > an= ything to Emacs, maybe you finally got rid of them (I hope)?
>= =C2=A0
> We no longer maintain ChangeLog files in the reposito= ry, but we do
> request commit log messages in the ChangeLog f= ormat, so please do
> provide them in the future. =C2=A0(I wro= te them for you this time.)

OK.

> I pushed the changes to the master branch, thanks.
Thank you.

> There's one poten= tial issue left:
>=C2=A0
> =C2=A0(func-arity '= ;with-temp-buffer) =3D> error-> Invalid function: with-temp-buffer
>=C2=A0
> Is it possible to support macros as well?= =C2=A0 If not, how about producing
> a more meaningful error m= essage?

Well, according to `functionp' macros = are not functions, so it's
sort of correct.=C2=A0 On the othe= r hand, it seems (symbol-function ...)
works, returning ('mac= ro . FUNCTION) for them.=C2=A0 However, I can't
find any real= C-level way to handle macros, e.g. `macrop' is even
not a bu= iltin.

Or is just treating them as lists fine?=C2= =A0 If so, we could add
something like this (untested):

diff --git a/src/eval.c b/src/eval.c
index 64a665= 5..5c594b8 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -2958,6 +2958,9 @@ function with `&rest' args, or `uneval= led' for a special form. =C2=A0*/)
=C2=A0 =C2=A0 =C2=A0 =C2= =A0&& (function =3D XSYMBOL (function)->function, SYMBOLP (funct= ion)))
=C2=A0 =C2=A0 =C2=A0function =3D indirect_function (functi= on);
=C2=A0
+ =C2=A0if (CONSP (function) && EQ = (XCAR (function), Qmacro))
+ =C2=A0 =C2=A0function =3D XCDR (func= tion);
+
=C2=A0 =C2=A0if (SUBRP (function))
= =C2=A0 =C2=A0 =C2=A0result =3D Fsubr_arity (function);
=C2=A0 =C2= =A0else if (COMPILEDP (function))

However, I'm= not exactly sure what will happen with autoloaded
macros.
<= div>
Paul
--001a11c2d0dae89a83052ef22b7b--