From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.bugs Subject: bug#17623: 24.4.50; incorrect example for `apply-partially' in (elisp) `Calling Functions' Date: Fri, 27 Jun 2014 18:36:04 -0700 (PDT) Message-ID: <1ac7ebe5-6b43-4367-beb8-df7d9f5b6750@default> References: <9fd43ff1-d6cf-4ac6-b173-2fd634f45a98@default> <871tua2o12.fsf@web.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1403919452 12875 80.91.229.3 (28 Jun 2014 01:37:32 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 28 Jun 2014 01:37:32 +0000 (UTC) Cc: 17623@debbugs.gnu.org To: Michael Heerdegen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Jun 28 03:37:25 2014 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1X0ha0-0003Qi-Ub for geb-bug-gnu-emacs@m.gmane.org; Sat, 28 Jun 2014 03:37:25 +0200 Original-Received: from localhost ([::1]:53206 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X0ha0-0001rd-8I for geb-bug-gnu-emacs@m.gmane.org; Fri, 27 Jun 2014 21:37:24 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43973) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X0hZo-0001r6-3k for bug-gnu-emacs@gnu.org; Fri, 27 Jun 2014 21:37:20 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X0hZf-0003RV-B3 for bug-gnu-emacs@gnu.org; Fri, 27 Jun 2014 21:37:11 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:44349) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X0hZf-0003RR-8E for bug-gnu-emacs@gnu.org; Fri, 27 Jun 2014 21:37:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1X0hZe-0004bm-IQ for bug-gnu-emacs@gnu.org; Fri, 27 Jun 2014 21:37:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Drew Adams Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 28 Jun 2014 01:37:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 17623 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 17623-submit@debbugs.gnu.org id=B17623.140391937917642 (code B ref 17623); Sat, 28 Jun 2014 01:37:02 +0000 Original-Received: (at 17623) by debbugs.gnu.org; 28 Jun 2014 01:36:19 +0000 Original-Received: from localhost ([127.0.0.1]:35499 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1X0hYw-0004aT-P0 for submit@debbugs.gnu.org; Fri, 27 Jun 2014 21:36:19 -0400 Original-Received: from userp1040.oracle.com ([156.151.31.81]:23856) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1X0hYt-0004aA-51 for 17623@debbugs.gnu.org; Fri, 27 Jun 2014 21:36:16 -0400 Original-Received: from ucsinet22.oracle.com (ucsinet22.oracle.com [156.151.31.94]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id s5S1a8CX007828 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 28 Jun 2014 01:36:09 GMT Original-Received: from userz7021.oracle.com (userz7021.oracle.com [156.151.31.85]) by ucsinet22.oracle.com (8.14.5+Sun/8.14.5) with ESMTP id s5S1a68p008692 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Sat, 28 Jun 2014 01:36:08 GMT Original-Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by userz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s5S1a5Xi005544; Sat, 28 Jun 2014 01:36:05 GMT In-Reply-To: <871tua2o12.fsf@web.de> X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.8 (707110) [OL 12.0.6691.5000 (x86)] X-Source-IP: ucsinet22.oracle.com [156.151.31.94] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:90926 Archived-At: > should we try to find a different example? Maybe something like > (defalias 'string-empty-p (apply-partially #'string=3D "")) ? Yes, we should. But forget about giving an example that (re)defines a function that is a built-in or is otherwise predefined. And again, it is better to have an example that illustrates and takes advantage of the fact that the function returned accepts any number of args. `string=3D' accepts only two args. The signature of `string-empty-p' shows that it accepts any number of arguments, and it says nothing about their type, but `string-empty-p' raises an error if it is passed anything other than 2 strings. Nothing wrong with that, but it is not so clear as an illustration of `apply-partially'. And it is better to have an example where the function passed does not have _only_ an &rest parameter (in which case it could be applied to just the first argument anyway). This example uses a function (+) that accepts any number of args, but its only parameter is an &rest parameter, so it is not a great way to show `apply-partially': (defalias '3+ (apply-partially '+ 3) "Return 3 plus the sum of the arguments.") (3+ 2 5 1) =3D> 11 That is better than an example that uses a function that accepts only a fixed number of arguments, but it is not as informative as examples like these, which accept a first arg that is a string and other args of any type. (defun present-list (frmt &rest things) "Use format string FRMT to present a list of THINGS." (format frmt things)) (defalias 'list-en (apply-partially #'present-list "The list: `%S'") "Return a string that presents a list of arguments.") (defalias 'list-fr (apply-partially #'present-list "La liste : `%S'") "Renvoyer une chaine qui presente use liste d'arguments.") (list-en 1 2 3) =3D> "The list: `(1 2 3)'" (list-fr '(x 42) '(y alpha)) =3D> "La liste : `((x 42) (y alpha))'" However, instead of (or in addition to) showing such an example, we could show the simple equivalence of these two (for all FUN, ARG1, and ARGS): (apply (apply-partially FUN ARG1) ARGS) =3D (apply FUN ARG1 ARGS) That alone tells users what `apply-partially' is all about.