unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: "Basil L. Contovounesios" <contovob@tcd.ie>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: 23736@debbugs.gnu.org, Rasmus <rasmus@gmx.us>
Subject: bug#23736: Add companion to apply-partially
Date: Sun, 28 Jul 2019 14:59:34 +0100	[thread overview]
Message-ID: <87r26al0op.fsf@tcd.ie> (raw)
In-Reply-To: <87zhkybbz0.fsf@mouse.gnus.org> (Lars Ingebrigtsen's message of "Sun, 28 Jul 2019 14:05:55 +0200")

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Rasmus <rasmus@gmx.us> writes:
>
>> Could we add an ‘apply-rpartially’ or ‘apply-partially-last’ to subr.el?
>> Like ‘apply-partially’, but fixing the last arguments.  This is useful for
>> e.g. ‘set-face-attribute’ where one might a common :inherits to many
>> faces, e.g.
>>
>>     (mapc (apply-rpartially ’set-face-attribute :inherit ’fixed-pitch) ’(list of faces))
>>
>> I have used this in my init.el,
>>
>>     (defun apply-rpartially (fun &rest args)
>>       "Return a function that is a partial application of FUN to ARGS.
>>     ARGS is a list of the last N arguments to pass to FUN.  The
>>     result is a new function which does the same as FUN, except that
>>     the last N arguments are fixed at the values with which this
>>     function was called."
>>       (lambda (&rest args1)
>>         (apply fun (append args1 args))))
>
> (I'm going through old Emacs bug reports that haven't received any
> response.)
>
> I think this sounds like a slightly too obscure function to add to Emacs
> core.  apply-partially is more useful because functions are often
> constructed in ways that makes that a convenient function, while the
> opposite order is more unusual, I think?

Indeed I think partial application from the right is not as generally
useful in languages with variadic functions.  IME it is often replaced
with shorthand for closures or currying from the right.

In the case of Elisp there is also the issue that apply-partially is
both a little verbose and (currently) significantly less efficient than
an open-coded closure.

-- 
Basil





      reply	other threads:[~2019-07-28 13:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-09 14:01 bug#23736: Add companion to apply-partially Rasmus
2019-07-28 12:05 ` Lars Ingebrigtsen
2019-07-28 13:59   ` Basil L. Contovounesios [this message]

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=87r26al0op.fsf@tcd.ie \
    --to=contovob@tcd.ie \
    --cc=23736@debbugs.gnu.org \
    --cc=larsi@gnus.org \
    --cc=rasmus@gmx.us \
    /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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).