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: Arbitrary function: find the number(s) of expected arguments Date: Tue, 15 Mar 2016 19:48:07 +0100 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a1136993a8f2c64052e1ad6f1 X-Trace: ger.gmane.org 1458073865 20283 80.91.229.3 (15 Mar 2016 20:31:05 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 15 Mar 2016 20:31:05 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Mar 15 21:31:05 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 1afvcO-0006zw-UW for ged-emacs-devel@m.gmane.org; Tue, 15 Mar 2016 21:31:05 +0100 Original-Received: from localhost ([::1]:51370 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1afvcO-0004sd-29 for ged-emacs-devel@m.gmane.org; Tue, 15 Mar 2016 16:31:04 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47196) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1afu0n-0007vc-CT for emacs-devel@gnu.org; Tue, 15 Mar 2016 14:48:10 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1afu0m-0005cW-7n for emacs-devel@gnu.org; Tue, 15 Mar 2016 14:48:09 -0400 Original-Received: from mail-ob0-x22b.google.com ([2607:f8b0:4003:c01::22b]:33927) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1afu0m-0005cM-30 for emacs-devel@gnu.org; Tue, 15 Mar 2016 14:48:08 -0400 Original-Received: by mail-ob0-x22b.google.com with SMTP id ts10so27185457obc.1 for ; Tue, 15 Mar 2016 11:48:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to; bh=3Wc2QCHnCXefCLJmZyUip1jcYeAXsJWPY3rjfXVm7jc=; b=ReY/JrN6aICZ3PpceJkGdZe5ifDtmYCNLhf1URK33Ds2qYxGBEvn/rDD9ZjjVziwXQ Ai5BRrfOoH7S/c0lNY6wLOijDvkyock8tMr/fMnXkg3/AmVmsT5RntoYi86Tt/ErBpB7 T1Q2/vckKTZrX3QHbQfbkT8CnNSwpLv2WpbiBSBI8RCjnotZC2mXcQaHsv8+Vg0HVVsg gr6aF8zY+QA1gjagiDKZGtdv1f+luq/aWMmuKopiq9JkH+QHZVPEHIeADP5owIObFqBE 84HD4tQ+sFQIRrJlHON492YJbJBu1mkoXfHzaK6iStn9PJz8hVDawCzidOoJFAwkRE+c IjzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to; bh=3Wc2QCHnCXefCLJmZyUip1jcYeAXsJWPY3rjfXVm7jc=; b=EsU5AqzM8ecUnN3/ubzHW8rHOZ4mSpUI6hQ1JMsywG5XRuH22V/JNoBRWcDrNhbOBs +s6cPREvoOHvd1e2u0AUePxBGTg1UYzVy987M4yYHqHxiaHAubw+O0JBwiK0ufPPfHRM +nb6xtzIxZEOjYXAC429Ul3ziyepUSRw+Gpqdd7UCXv3++bTMKzCe6v3kU1w/ksnYU4J ZB38M+ORr0GZdK1ik2pkqCq0zjrP27Cu3zD9/8kpXLD9/yFa1QPH2OSS4AJsXMg746x0 1o1UgNd904w4TPSwF+TgD/z4FR/7S4oGDH6p5AQ7fW+LrUejuDw1GxmHmAYBJFvHEabK dgHA== X-Gm-Message-State: AD7BkJIzJJnuFWhGQaP7F0sSFjxfbxprJvxUaKHcqRs3T4+zYuz5OvdGLuegAt2wp263rUl+WCv6fIHbCI6nIw== X-Received: by 10.60.246.72 with SMTP id xu8mr19688954oec.71.1458067687285; Tue, 15 Mar 2016 11:48:07 -0700 (PDT) Original-Received: by 10.202.71.7 with HTTP; Tue, 15 Mar 2016 11:48:07 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4003:c01::22b X-Mailman-Approved-At: Tue, 15 Mar 2016 16:30:50 -0400 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:201786 Archived-At: --001a1136993a8f2c64052e1ad6f1 Content-Type: text/plain; charset=UTF-8 Hi, Suppose I have a library with (defun my-foo (callback) ... (funcall callback computed-data)) Now, _some_ users of my library found out that it would be nice to have `this-value-gets-computed-as-side-effect' too, though it is not really necessary for callbacks in general. I wouldn't want to change interface of the library, instead I would just improve it like this: (defun my-foo (callback) ... (if (accepts-2-arguments callback) (funcall callback computed-data this-value-gets-computed-as-side-effect) (funcall callback computed-data))) This way `my-foo' automagically accepts callbacks that expect one argument (as in initial form), as well as those that want two arguments. The problem, of course, is to write `accepts-2-arguments'. I found `subr-arity', which provides exactly what I need, but only for builtins... I was also told about `help-function-arglist', but it returns the raw argument list in which you still have to handle &optional or &rest (maybe something else too?). This looks like a bit too much work for simple thing and likely not good for performance-critical places either. Feature request: add a builtin like `subr-arity' that works for _any_ function. Evaluator sure knows how to call the functions, so the information is already there. Paul --001a1136993a8f2c64052e1ad6f1 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi,

Suppose I have a library with
=

=C2=A0 =C2=A0 (defun my-foo (callback)
=C2=A0= =C2=A0 =C2=A0 ...
=C2=A0 =C2=A0 =C2=A0 (funcall callback compute= d-data))

Now, _some_ users of my library found out= that it would be nice to have `this-value-gets-computed-as-side-effect'= ; too, though it is not really necessary for callbacks in general. I wouldn= 't want to change interface of the library, instead I would just improv= e it like this:

=C2=A0 =C2=A0 (defun my-foo (= callback)
=C2=A0 =C2=A0 =C2=A0 ...
=C2=A0 =C2=A0 =C2=A0= (if (accepts-2-arguments callback)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 (funcall callback computed-data this-value-gets-computed-as-side-eff= ect)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (funcall callback computed-data)= ))

This way `my-foo' automagically accep= ts callbacks that expect one argument (as in initial form), as well as thos= e that want two arguments.

The problem, of course,= is to write `accepts-2-arguments'.=C2=A0 I found `subr-arity', whi= ch provides exactly what I need, but only for builtins... I was also told a= bout `help-function-arglist', but it returns the raw argument list in w= hich you still have to handle &optional or &rest (maybe something e= lse too?). This looks like a bit too much work for simple thing and likely = not good for performance-critical places either.

F= eature request: add a builtin like `subr-arity' that works for _any_ fu= nction. Evaluator sure knows how to call the functions, so the information = is already there.

Paul
--001a1136993a8f2c64052e1ad6f1--