From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Philipp Stephani Newsgroups: gmane.emacs.devel Subject: Re: Arbitrary function: find the number(s) of expected arguments Date: Sat, 19 Mar 2016 16:46:29 +0000 Message-ID: References: <56E8906C.5050405@lanl.gov> <83egb68vfy.fsf@gnu.org> <87zituefp9.fsf@web.de> <83a8lu8srs.fsf@gnu.org> <87twk2ebp2.fsf@web.de> <838u1e8od1.fsf@gnu.org> <8360wi8mbo.fsf@gnu.org> <834mc28m3j.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a1140c8ec8bf9d6052e699b0b X-Trace: ger.gmane.org 1458406021 6736 80.91.229.3 (19 Mar 2016 16:47:01 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 19 Mar 2016 16:47:01 +0000 (UTC) Cc: michael_heerdegen@web.de, emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Mar 19 17:46:58 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 1ahK1h-00004s-9K for ged-emacs-devel@m.gmane.org; Sat, 19 Mar 2016 17:46:57 +0100 Original-Received: from localhost ([::1]:49672 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ahK1g-0006kK-KL for ged-emacs-devel@m.gmane.org; Sat, 19 Mar 2016 12:46:56 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34081) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ahK1S-0006ic-19 for emacs-devel@gnu.org; Sat, 19 Mar 2016 12:46:42 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ahK1R-0006SN-3T for emacs-devel@gnu.org; Sat, 19 Mar 2016 12:46:41 -0400 Original-Received: from mail-lf0-x232.google.com ([2a00:1450:4010:c07::232]:36629) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ahK1Q-0006SJ-Mq; Sat, 19 Mar 2016 12:46:41 -0400 Original-Received: by mail-lf0-x232.google.com with SMTP id d82so37962875lfe.3; Sat, 19 Mar 2016 09:46:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=1128U9s+4H7ckF4xtw2/rltVsdz6eiMMpaMeJv5JlDY=; b=BJ4BpAq1rYMyUeEHhPpEgDFr7psBBp+BJpucWe7YnDft2iwWCOO0pu/ulw30k6/iZH cSCRrhdGO4OugVotAeq7/29r6LLhvI8UFODnefo7digyQ53fZUoZ6MwyBHRocXDBUdxE jrInFLfH+XRbHXEr4ft2EJ50BGXim4z2SRmBildo6AHoB2Jk8Qp9ZW8qjSbERt66LIxI Ox4jSdz6EqwOlM/PNoM6wzEhql028Y14t5qhWuAReke5YDJ5SHtuV8RmK0NriiIgVjK+ zKmfk4/L8rUXBh6LdO+4d6IUHqzwKkuhGGhBkyLSfgiwtQg8jqVQ4uXS6sy/CkbEb6CS +wkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=1128U9s+4H7ckF4xtw2/rltVsdz6eiMMpaMeJv5JlDY=; b=D5spt1+utAm69RUYlr5Dyfn7QvwyXnEYyyId28P3KP8aGfXfaWyn3K6CezDmIWjdbb ua6lJuz/NBBME2gsv8WEmFbL934CMd5fC1T02W806IfXWHJa27GBddzHESorANiJhiO1 mg6Lj9yzJIUP4f8SpKOBh9rAjC8T4DMJX92lGgL/oWcnfklcQ/CcNq5Fv2caK7FYovEV 0O4efJVHoJiO0mnlZ7X7b7qMTY9Mva1G2WwCMeMD/H3CzQSunz3JhD7Xs5mW4aTKWSm8 K5GNLpSuYUAp6pVEZoZXPYSY7yEM2KqUBFFiQUrq8KqLdaqARtfCn7fidVF2LJGk7kRP u9Hg== X-Gm-Message-State: AD7BkJLoPQ6R0bZjNsOKcmaKEpTJDjJbSb5ydxBXoJtTZn8OQGbdKQuuu5XcxlnWhnTeKVmd90YRUORHBVDxng== X-Received: by 10.25.212.213 with SMTP id l204mr8166679lfg.118.1458405999636; Sat, 19 Mar 2016 09:46:39 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c07::232 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:201880 Archived-At: --001a1140c8ec8bf9d6052e699b0b Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Philipp Stephani schrieb am Sa., 19. M=C3=A4rz 2016= um 17:34 Uhr: > Eli Zaretskii schrieb am Sa., 19. M=C3=A4rz 2016 um 17:33 = Uhr: > >> > From: Philipp Stephani >> > Date: Sat, 19 Mar 2016 16:30:30 +0000 >> > Cc: michael_heerdegen@web.de, emacs-devel@gnu.org >> > >> > No, that's not g's arity: >> > >> > (g 10 202 30) =3D> error -> "Wrong number of arguments" >> > >> > This cannot be detected without evaluating the function. >> >> Are we discussing the usefulness of the function, or are we discussing >> how best to implement it? >> > > We are discussing for which cases it can be implemented. It can be > implemented and would be useful for a wide range of functions, such as > those defined with defun. > Example implementation (doesn't work with macros): (defun function-arity (function) (setq function (indirect-function function)) (cl-check-type function function) (if (subrp function) (subr-arity function) (let ((min 0) (max 0) optional) (dolist (arg (help-function-arglist function) (cons min max)) (cond ((eq max 'many)) ((eq arg '&optional) (setq optional t)) ((eq arg '&rest) (setq max 'many)) (t (unless optional (cl-incf min)) (cl-incf max))))))) --001a1140c8ec8bf9d6052e699b0b Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable


Philip= p Stephani <p.stephani2@gmail.c= om> schrieb am Sa., 19. M=C3=A4rz 2016 um 17:34=C2=A0Uhr:
<= blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px= #ccc solid;padding-left:1ex">
<= div dir=3D"ltr">Eli Zaretskii <eliz@gnu.org> schrieb am Sa., 19. M=C3=A4rz 2016 um 17:33= =C2=A0Uhr:
> From: Philipp Steph= ani <p.stepha= ni2@gmail.com>
> Date: Sat, 19 Mar 2016 16:30:30 +0000
> Cc: mich= ael_heerdegen@web.de, emacs-devel@gnu.org
>
>=C2=A0 No, that's not g's arity:
>
>=C2=A0 (g 10 202 30) =3D> error -> "Wrong number of argument= s"
>
> This cannot be detected without evaluating the function.

Are we discussing the usefulness of the function, or are we discussing
how best to implement it?

We are discussing for which case= s it can be implemented. It can be implemented and would be useful for a wi= de range of functions, such as those defined with defun.
<= /blockquote>

Example implementation (doesn't work wi= th macros):

(defun function-arity (function)
=
=C2=A0 (setq function (indirect-function function))
=C2=A0 (= cl-check-type function function)
=C2=A0 (if (subrp function)
=C2=A0 =C2=A0 =C2=A0 (subr-arity function)
=C2=A0 =C2=A0 (l= et ((min 0) (max 0) optional)
=C2=A0 =C2=A0 =C2=A0 (dolist (arg (= help-function-arglist function) (cons min max))
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 (cond
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0((eq max '= many))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0((eq arg '&optio= nal) (setq optional t))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0((eq ar= g '&rest) (setq max 'many))
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0(t
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (unless optional = (cl-incf min))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (cl-incf max)))= ))))
--001a1140c8ec8bf9d6052e699b0b--