all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: Michael Heerdegen <michael_heerdegen@web.de>
Cc: 17623@debbugs.gnu.org
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)	[thread overview]
Message-ID: <1ac7ebe5-6b43-4367-beb8-df7d9f5b6750@default> (raw)
In-Reply-To: <871tua2o12.fsf@web.de>

> should we try to find a different example?  Maybe something like
> (defalias 'string-empty-p (apply-partially #'string= "")) ?

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=' 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)
    => 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)
    => "The list: `(1 2 3)'"

(list-fr '(x 42) '(y alpha))
    => "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) = (apply FUN ARG1 ARGS)

That alone tells users what `apply-partially' is all about.





  reply	other threads:[~2014-06-28  1:36 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-28 23:53 bug#17623: 24.4.50; incorrect example for `apply-partially' in (elisp) `Calling Functions' Drew Adams
2014-06-27 18:41 ` Michael Heerdegen
2014-06-28  1:36   ` Drew Adams [this message]
2014-06-28 15:53     ` Michael Heerdegen
2014-06-28 16:55       ` Eli Zaretskii
2014-06-28 17:53         ` Michael Heerdegen
2014-06-28 18:45           ` Eli Zaretskii
2014-06-28 19:37             ` Michael Heerdegen
2014-06-29 14:57               ` Eli Zaretskii
2021-10-23  5:24             ` Stefan Kangas
2021-10-23  9:44               ` Michael Heerdegen
2021-10-23 11:05                 ` Stefan Kangas
2021-10-23 11:58                   ` Michael Heerdegen
2021-10-23 11:39                 ` Eli Zaretskii
2021-10-23 12:44                   ` Michael Heerdegen
2021-10-23 13:13                     ` Eli Zaretskii
2021-10-23 15:29                       ` Michael Heerdegen
2021-10-23 17:01                         ` Stefan Kangas
2021-10-26  9:26                           ` Michael Heerdegen
2021-10-26 20:24                             ` Stefan Kangas
2021-10-27  9:18                               ` Michael Heerdegen
2021-10-29  4:02                               ` Richard Stallman
2021-10-29 10:00                                 ` Michael Heerdegen
2021-10-23 17:54                         ` Eli Zaretskii
2021-10-23 13:14                     ` Stefan Kangas
2021-10-23 15:38                       ` Michael Heerdegen
2021-10-23 17:57                         ` Eli Zaretskii
     [not found]           ` <<83tx746fgd.fsf@gnu.org>
2014-06-28 19:32             ` Drew Adams
2014-06-29 21:46           ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1ac7ebe5-6b43-4367-beb8-df7d9f5b6750@default \
    --to=drew.adams@oracle.com \
    --cc=17623@debbugs.gnu.org \
    --cc=michael_heerdegen@web.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.