bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#23736: Add companion to apply-partially


From: Basil L. Contovounesios
Subject: bug#23736: Add companion to apply-partially
Date: Sun, 28 Jul 2019 14:59:34 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

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 via email to

[Prev in Thread] Current Thread [Next in Thread]