* bug#23736: Add companion to apply-partially
@ 2016-06-09 14:01 Rasmus
2019-07-28 12:05 ` Lars Ingebrigtsen
0 siblings, 1 reply; 3+ messages in thread
From: Rasmus @ 2016-06-09 14:01 UTC (permalink / raw)
To: 23736
Hi,
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))))
If that’s good I can prepare a patch that also has documentation. (I
couldn’t find past discussions about such a function)
Rasmus
--
Don't slow down Johnny, leave the Cadillac runnin'
^ permalink raw reply [flat|nested] 3+ messages in thread
* bug#23736: Add companion to apply-partially
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
0 siblings, 1 reply; 3+ messages in thread
From: Lars Ingebrigtsen @ 2019-07-28 12:05 UTC (permalink / raw)
To: Rasmus; +Cc: 23736
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?
(And especially with lexical support doing this sort of thing is often
easier, anyway.)
So I'm closing this as a "wontfix".
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 3+ messages in thread
* bug#23736: Add companion to apply-partially
2019-07-28 12:05 ` Lars Ingebrigtsen
@ 2019-07-28 13:59 ` Basil L. Contovounesios
0 siblings, 0 replies; 3+ messages in thread
From: Basil L. Contovounesios @ 2019-07-28 13:59 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: 23736, Rasmus
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-07-28 13:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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.