Subject: bug#49316: Add apply-partially's right version

From: daanturo <[email-masked]>
Date: Thu, 1 Jul 2021 23:24:22 +0700

Added documentation in doc/lispref/functions.texi and etc/NEWS.

Thank you.

On 7/1/21 8:11 PM, Basil L. Contovounesios wrote:
> tags 49316 + patch
> quit
>
>>  From c594d6fc396b80019c48e63918f8c5e485f2782f Mon Sep 17 00:00:00 2001
>> From: Daanturo <[email-masked]>
>> Date: Thu, 1 Jul 2021 19:21:08 +0700
>> Subject: [PATCH] Define apply-rpatially
>                                  ^^^^^^^^^
>                                  rpartially
>
>> Which is analogous to `apply-partially` but arguments are aligned on the right
>> instead.
> Nit: Missing changelog-style entry (see the guidelines in the file
> CONTRIBUTE), e.g.:
>
> * lisp/subr.el (apply-rpartially): New function.
>
>>   lisp/subr.el | 9 +++++++++
>>   1 file changed, 9 insertions(+)
> This feature would probably also warrant an announcement in etc/NEWS and
> a manual entry under (info "(elisp) Calling Functions").
>
> Thanks,
>
-- 
Daanturo.

>From b56a83f2765d3dfb1db011acc561bf107c934594 Mon Sep 17 00:00:00 2001
From: Daanturo <[email-masked]>
Date: Thu, 1 Jul 2021 23:01:42 +0700
Subject: [PATCH 2/2] Add apply-rpartially documents

* doc/lispref/functions.texi (Calling Functions): Add explanation and
example usage
* etc/NEWS (Lisp Changes in Emacs 28.1): Announce new function
---
 doc/lispref/functions.texi | 17 +++++++++++++++++
 etc/NEWS                   |  5 +++++
 2 files changed, 22 insertions(+)

diff --git a/doc/lispref/functions.texi b/doc/lispref/functions.texi
index 64883bf0f6..80d0c96687 100644
--- a/doc/lispref/functions.texi
+++ b/doc/lispref/functions.texi
@@ -845,6 +845,23 @@ built-in function:
 @end example
 @end defun
 
+@defun apply-rpartially func &rest args
+This function does mostly the same as @code{apply-partially}, but
+@var{args} are aligned to the right of @var{func}'s parameters
+instead.
+
+@example
+@group
+(defalias 'square (apply-rpartially #'expt 2)
+  "Return argument squared.")
+@end group
+@group
+(square 3)
+     @result{} 9
+@end group
+@end example
+@end defun
+
 @cindex functionals
   It is common for Lisp functions to accept functions as arguments or
 find them in data structures (especially in hook variables and property
diff --git a/etc/NEWS b/etc/NEWS
index 605c4d228f..252e6b4d0b 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2909,6 +2909,11 @@ The former is now declared obsolete.
 
 * Lisp Changes in Emacs 28.1
 
++++
+** New function 'apply-rpartially'.
+Funcionally equivalent to 'apply-partially' but arguments are aligned
+to the right instead.
+
 +++
 ** New function 'syntax-class-to-char'.
 This does almost the opposite of 'string-to-syntax' -- it returns the
-- 
2.32.0

>From 6af0d300d214c3fcf872641356a6c788b0aed771 Mon Sep 17 00:00:00 2001
From: Daanturo <[email-masked]>
Date: Thu, 1 Jul 2021 22:03:05 +0700
Subject: [PATCH 1/2] Define apply-rpartially

* lisp/subr.el (apply-rpartially): New function which is analogous to
`apply-partially` but arguments are aligned on the right instead.
---
 lisp/subr.el | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/lisp/subr.el b/lisp/subr.el
index e49c277335..5965655d48 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -465,6 +465,15 @@ was called."
   (lambda (&rest args2)
     (apply fun (append args args2))))
 
+(defun apply-rpartially (fun &rest args)
+  "Return a function that is a partial application of FUN to ARGS to the right.
+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))))
+
 (defun zerop (number)
   "Return t if NUMBER is zero."
   ;; Used to be in C, but it's pointless since (= 0 n) is faster anyway because
-- 
2.32.0