* bug#49316: Add apply-partially's right version
@ 2021-07-01 12:40 daanturo
2021-07-01 13:11 ` Basil L. Contovounesios
2021-07-01 22:34 ` Michael Heerdegen
0 siblings, 2 replies; 28+ messages in thread
From: daanturo @ 2021-07-01 12:40 UTC (permalink / raw)
To: 49316
[-- Attachment #1: Type: text/plain, Size: 2318 bytes --]
--=-=-=
Content-Type: text/plain
Tags: patch
Define apply-rpartial.
The equivalent function in dash.el is widely used by other packages so
it's beneficial to include it by default.
In GNU Emacs 28.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
3.24.29, cairo version 1.17.4)
of 2021-06-25 built on c6
Repository revision: e288348c0a785537d95b7ef2fff0cda729a29677
Repository branch: makepkg
Windowing system distributor 'System Description: Arch Linux
Configured using:
'configure --prefix=/usr --sysconfdir=/etc --libexecdir=/usr/lib
--localstatedir=/var --mandir=/usr/share/man --with-gameuser=:games
--with-sound=alsa --with-modules --without-gconf --without-gsettings
--with-native-compilation --with-pgtk --with-x-toolkit=gtk3
--without-xaw3d --without-m17n-flt --with-cairo --with-xwidgets
--without-compress-install 'CFLAGS=-march=x86-64 -mtune=generic -O2
-pipe -fno-plt -fexceptions -Wp,-D_FORTIFY_SOURCE=2 -Wformat
-Werror=format-security -fstack-clash-protection -fcf-protection -g
-fuse-ld=gold -g -fuse-ld=gold'
LDFLAGS=-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now'
--=-=-=
Content-Type: text/patch
Content-Disposition: attachment; filename=0001-Define-apply-rpatially.patch
From c594d6fc396b80019c48e63918f8c5e485f2782f Mon Sep 17 00:00:00 2001
From: Daanturo <daanturo@gmail.com>
Date: Thu, 1 Jul 2021 19:21:08 +0700
Subject: [PATCH] Define apply-rpatially
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
--=-=-=--
--
Daanturo.
[-- Attachment #2: 0001-Define-apply-rpatially.patch --]
[-- Type: text/x-patch, Size: 1103 bytes --]
From c594d6fc396b80019c48e63918f8c5e485f2782f Mon Sep 17 00:00:00 2001
From: Daanturo <daanturo@gmail.com>
Date: Thu, 1 Jul 2021 19:21:08 +0700
Subject: [PATCH] Define apply-rpatially
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
^ permalink raw reply related [flat|nested] 28+ messages in thread
* bug#49316: Add apply-partially's right version
2021-07-01 12:40 bug#49316: Add apply-partially's right version daanturo
@ 2021-07-01 13:11 ` Basil L. Contovounesios
2021-07-01 16:24 ` daanturo
2021-07-01 22:34 ` Michael Heerdegen
1 sibling, 1 reply; 28+ messages in thread
From: Basil L. Contovounesios @ 2021-07-01 13:11 UTC (permalink / raw)
To: daanturo; +Cc: 49316
tags 49316 + patch
quit
> From c594d6fc396b80019c48e63918f8c5e485f2782f Mon Sep 17 00:00:00 2001
> From: Daanturo <daanturo@gmail.com>
> 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,
--
Basil
^ permalink raw reply [flat|nested] 28+ messages in thread
* bug#49316: Add apply-partially's right version
2021-07-01 13:11 ` Basil L. Contovounesios
@ 2021-07-01 16:24 ` daanturo
2021-07-01 17:06 ` daanturo
0 siblings, 1 reply; 28+ messages in thread
From: daanturo @ 2021-07-01 16:24 UTC (permalink / raw)
To: 49316; +Cc: Basil L. Contovounesios
[-- Attachment #1: Type: text/plain, Size: 920 bytes --]
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 <daanturo@gmail.com>
>> 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.
[-- Attachment #2: 0002-Add-apply-rpartially-documents.patch --]
[-- Type: text/x-patch, Size: 1709 bytes --]
From b56a83f2765d3dfb1db011acc561bf107c934594 Mon Sep 17 00:00:00 2001
From: Daanturo <daanturo@gmail.com>
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.
\f
* 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
[-- Attachment #3: 0001-Define-apply-rpartially.patch --]
[-- Type: text/x-patch, Size: 1156 bytes --]
From 6af0d300d214c3fcf872641356a6c788b0aed771 Mon Sep 17 00:00:00 2001
From: Daanturo <daanturo@gmail.com>
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
^ permalink raw reply related [flat|nested] 28+ messages in thread
* bug#49316: Add apply-partially's right version
2021-07-01 16:24 ` daanturo
@ 2021-07-01 17:06 ` daanturo
2021-07-01 17:16 ` daanturo
2021-07-01 18:45 ` Eli Zaretskii
0 siblings, 2 replies; 28+ messages in thread
From: daanturo @ 2021-07-01 17:06 UTC (permalink / raw)
To: 49316; +Cc: Basil L. Contovounesios
[-- Attachment #1: Type: text/plain, Size: 2067 bytes --]
--=-=-=
Content-Type: text/plain
Tags: 49316 + patch
Added documentation in doc/lispref/functions.texi and etc/NEWS.
(Please ignore my immediately precededing email, I'm sorry for not being
used to sending patches by mailing list.)
Thank you.
--=-=-=
Content-Type: text/patch
Content-Disposition: attachment;
filename=0002-Add-apply-rpartially-documents.patch
From b56a83f2765d3dfb1db011acc561bf107c934594 Mon Sep 17 00:00:00 2001
From: Daanturo <daanturo@gmail.com>
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.
\f
* 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
--=-=-=--
--
Daanturo.
[-- Attachment #2: 0002-Add-apply-rpartially-documents.patch --]
[-- Type: text/x-patch, Size: 1709 bytes --]
From b56a83f2765d3dfb1db011acc561bf107c934594 Mon Sep 17 00:00:00 2001
From: Daanturo <daanturo@gmail.com>
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.
\f
* 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
^ permalink raw reply related [flat|nested] 28+ messages in thread
* bug#49316: Add apply-partially's right version
2021-07-01 17:06 ` daanturo
@ 2021-07-01 17:16 ` daanturo
2021-07-01 18:45 ` Eli Zaretskii
1 sibling, 0 replies; 28+ messages in thread
From: daanturo @ 2021-07-01 17:16 UTC (permalink / raw)
To: 49316; +Cc: Basil L. Contovounesios
[-- Attachment #1: Type: text/plain, Size: 1004 bytes --]
--=-=-=
Content-Type: text/plain
Tags: 49316 + patch
Fix apply-rpartially's typo in etc/NEWS
--=-=-=
Content-Type: text/patch
Content-Disposition: attachment;
filename=0001-Fix-apply-rpartially-s-typo-in-etc-NEWS.patch
From 002c1025b6aee1d112fe6b918384615b5ec9949c Mon Sep 17 00:00:00 2001
From: Daanturo <daanturo@gmail.com>
Date: Fri, 2 Jul 2021 00:11:12 +0700
Subject: [PATCH] Fix apply-rpartially's typo in etc/NEWS
* etc/NEWS (Lisp Changes in Emacs 28.1): fix apply-rpartially's typo:
Funcionally -> Functionally
---
etc/NEWS | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/etc/NEWS b/etc/NEWS
index 252e6b4d0b..be30d6c859 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2911,7 +2911,7 @@ The former is now declared obsolete.
+++
** New function 'apply-rpartially'.
-Funcionally equivalent to 'apply-partially' but arguments are aligned
+Functionally equivalent to 'apply-partially' but arguments are aligned
to the right instead.
+++
--
2.32.0
--=-=-=--
--
Daanturo.
[-- Attachment #2: 0001-Fix-apply-rpartially-s-typo-in-etc-NEWS.patch --]
[-- Type: text/x-patch, Size: 758 bytes --]
From 002c1025b6aee1d112fe6b918384615b5ec9949c Mon Sep 17 00:00:00 2001
From: Daanturo <daanturo@gmail.com>
Date: Fri, 2 Jul 2021 00:11:12 +0700
Subject: [PATCH] Fix apply-rpartially's typo in etc/NEWS
* etc/NEWS (Lisp Changes in Emacs 28.1): fix apply-rpartially's typo:
Funcionally -> Functionally
---
etc/NEWS | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/etc/NEWS b/etc/NEWS
index 252e6b4d0b..be30d6c859 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2911,7 +2911,7 @@ The former is now declared obsolete.
+++
** New function 'apply-rpartially'.
-Funcionally equivalent to 'apply-partially' but arguments are aligned
+Functionally equivalent to 'apply-partially' but arguments are aligned
to the right instead.
+++
--
2.32.0
^ permalink raw reply related [flat|nested] 28+ messages in thread
* bug#49316: Add apply-partially's right version
2021-07-01 17:06 ` daanturo
2021-07-01 17:16 ` daanturo
@ 2021-07-01 18:45 ` Eli Zaretskii
2021-07-02 2:49 ` daanturo
2021-07-02 16:32 ` daanturo
1 sibling, 2 replies; 28+ messages in thread
From: Eli Zaretskii @ 2021-07-01 18:45 UTC (permalink / raw)
To: daanturo; +Cc: contovob, 49316
> From: daanturo <daanturo@gmail.com>
> Date: Fri, 2 Jul 2021 00:06:35 +0700
> Cc: "Basil L. Contovounesios" <contovob@tcd.ie>
>
> (Please ignore my immediately precededing email, I'm sorry for not being
> used to sending patches by mailing list.)
I see no problems in the preceding email, so I think you have nothing
to apologize for.
> +@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.
I don't think this explains the purpose of the function clearly
enough. The documentation of apply-partially doesn't mention any
"alignment", so it's hard to understand what you want to say here.
Can you think of a better description?
> +@example
> +@group
> +(defalias 'square (apply-rpartially #'expt 2)
> + "Return argument squared.")
> +@end group
> +@group
> +(square 3)
> + @result{} 9
> +@end group
> +@end example
IMO, the example could be more revealing if you could contrast
apply-rpartially with apply-partially.
> ++++
> +** New function 'apply-rpartially'.
> +Funcionally equivalent to 'apply-partially' but arguments are aligned
> +to the right instead.
After we find a good wording for the manual, we should think how to
reword the NEWS entry accordingly.
Thanks.
^ permalink raw reply [flat|nested] 28+ messages in thread
* bug#49316: Add apply-partially's right version
2021-07-01 18:45 ` Eli Zaretskii
@ 2021-07-02 2:49 ` daanturo
2021-07-03 7:03 ` Eli Zaretskii
2021-07-02 16:32 ` daanturo
1 sibling, 1 reply; 28+ messages in thread
From: daanturo @ 2021-07-02 2:49 UTC (permalink / raw)
To: 49316; +Cc: contovob
[-- Attachment #1: Type: text/plain, Size: 3210 bytes --]
--=-=-=
Content-Type: text/plain
Tags: patch
I have replaced the examples:
(defalias '**2 (apply-rpartially #'expt 2)
"Return argument ** 2.")
(defalias '2** (apply-partially #'expt 2)
"Return 2 ** argument.")
(**2 3)
=> 9
(2** 3)
=> 8
--=-=-=
Content-Type: text/patch
Content-Disposition: attachment;
filename=0004-Better-apply-rpartially-documentation.patch
From ab6977b40a4d2be418716c16bb0d38c35e62b62f Mon Sep 17 00:00:00 2001
From: Daanturo <daanturo@gmail.com>
Date: Fri, 2 Jul 2021 09:43:27 +0700
Subject: [PATCH] Better apply-rpartially documentation
* doc/lispref/functions.texi (Calling Functions): provide comparison
with apply-partially
---
doc/lispref/functions.texi | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/doc/lispref/functions.texi b/doc/lispref/functions.texi
index 80d0c96687..9e08affd1e 100644
--- a/doc/lispref/functions.texi
+++ b/doc/lispref/functions.texi
@@ -847,17 +847,21 @@ built-in function:
@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.
+@var{args} are the last arguments to be passed to @var{func}'s
+parameters instead.
@example
@group
-(defalias 'square (apply-rpartially #'expt 2)
- "Return argument squared.")
+(defalias '**2 (apply-rpartially #'expt 2)
+ "Return argument ** 2.")
+(defalias '2** (apply-partially #'expt 2)
+ "Return 2 ** argument.")
@end group
@group
-(square 3)
+(**2 3)
@result{} 9
+(2** 3)
+ @result{} 8
@end group
@end example
@end defun
--
2.32.0
--=-=-=--
On 7/2/21 1:45 AM, Eli Zaretskii wrote:
>> From: daanturo <daanturo@gmail.com>
>> Date: Fri, 2 Jul 2021 00:06:35 +0700
>> Cc: "Basil L. Contovounesios" <contovob@tcd.ie>
>>
>> (Please ignore my immediately precededing email, I'm sorry for not being
>> used to sending patches by mailing list.)
> I see no problems in the preceding email, so I think you have nothing
> to apologize for.
>
>> +@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.
> I don't think this explains the purpose of the function clearly
> enough. The documentation of apply-partially doesn't mention any
> "alignment", so it's hard to understand what you want to say here.
> Can you think of a better description?
>
>> +@example
>> +@group
>> +(defalias 'square (apply-rpartially #'expt 2)
>> + "Return argument squared.")
>> +@end group
>> +@group
>> +(square 3)
>> + @result{} 9
>> +@end group
>> +@end example
> IMO, the example could be more revealing if you could contrast
> apply-rpartially with apply-partially.
>
>> ++++
>> +** New function 'apply-rpartially'.
>> +Funcionally equivalent to 'apply-partially' but arguments are aligned
>> +to the right instead.
> After we find a good wording for the manual, we should think how to
> reword the NEWS entry accordingly.
>
> Thanks.
--
Daanturo.
[-- Attachment #2: 0004-Better-apply-rpartially-documentation.patch --]
[-- Type: text/x-patch, Size: 1250 bytes --]
From ab6977b40a4d2be418716c16bb0d38c35e62b62f Mon Sep 17 00:00:00 2001
From: Daanturo <daanturo@gmail.com>
Date: Fri, 2 Jul 2021 09:43:27 +0700
Subject: [PATCH] Better apply-rpartially documentation
* doc/lispref/functions.texi (Calling Functions): provide comparison
with apply-partially
---
doc/lispref/functions.texi | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/doc/lispref/functions.texi b/doc/lispref/functions.texi
index 80d0c96687..9e08affd1e 100644
--- a/doc/lispref/functions.texi
+++ b/doc/lispref/functions.texi
@@ -847,17 +847,21 @@ built-in function:
@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.
+@var{args} are the last arguments to be passed to @var{func}'s
+parameters instead.
@example
@group
-(defalias 'square (apply-rpartially #'expt 2)
- "Return argument squared.")
+(defalias '**2 (apply-rpartially #'expt 2)
+ "Return argument ** 2.")
+(defalias '2** (apply-partially #'expt 2)
+ "Return 2 ** argument.")
@end group
@group
-(square 3)
+(**2 3)
@result{} 9
+(2** 3)
+ @result{} 8
@end group
@end example
@end defun
--
2.32.0
^ permalink raw reply related [flat|nested] 28+ messages in thread
* bug#49316: Add apply-partially's right version
2021-07-02 2:49 ` daanturo
@ 2021-07-03 7:03 ` Eli Zaretskii
2021-10-24 6:55 ` Stefan Kangas
0 siblings, 1 reply; 28+ messages in thread
From: Eli Zaretskii @ 2021-07-03 7:03 UTC (permalink / raw)
To: daanturo; +Cc: contovob, 49316
> Cc: contovob@tcd.ie, Eli Zaretskii <eliz@gnu.org>
> From: daanturo <daanturo@gmail.com>
> Date: Fri, 2 Jul 2021 09:49:19 +0700
>
> I have replaced the examples:
>
>
> (defalias '**2 (apply-rpartially #'expt 2)
> "Return argument ** 2.")
> (defalias '2** (apply-partially #'expt 2)
> "Return 2 ** argument.")
> (**2 3)
> => 9
> (2** 3)
> => 8
Thanks, the patch LGTM.
^ permalink raw reply [flat|nested] 28+ messages in thread
* bug#49316: Add apply-partially's right version
2021-07-03 7:03 ` Eli Zaretskii
@ 2021-10-24 6:55 ` Stefan Kangas
2021-10-24 10:49 ` daanturo
2021-10-24 13:38 ` Lars Ingebrigtsen
0 siblings, 2 replies; 28+ messages in thread
From: Stefan Kangas @ 2021-10-24 6:55 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: contovob, daanturo, 49316
Eli Zaretskii <eliz@gnu.org> writes:
>> Cc: contovob@tcd.ie, Eli Zaretskii <eliz@gnu.org>
>> From: daanturo <daanturo@gmail.com>
>> Date: Fri, 2 Jul 2021 09:49:19 +0700
>>
>> I have replaced the examples:
>>
>>
>> (defalias '**2 (apply-rpartially #'expt 2)
>> "Return argument ** 2.")
>> (defalias '2** (apply-partially #'expt 2)
>> "Return 2 ** argument.")
>> (**2 3)
>> => 9
>> (2** 3)
>> => 8
>
> Thanks, the patch LGTM.
It seems like neither this nor any of the other patches in this bug
report were applied.
Do we have a copyright assignment for daanturo <daanturo@gmail.com> on
file?
^ permalink raw reply [flat|nested] 28+ messages in thread
* bug#49316: Add apply-partially's right version
2021-10-24 6:55 ` Stefan Kangas
@ 2021-10-24 10:49 ` daanturo
2021-10-24 11:18 ` Stefan Kangas
2021-10-24 13:38 ` Lars Ingebrigtsen
1 sibling, 1 reply; 28+ messages in thread
From: daanturo @ 2021-10-24 10:49 UTC (permalink / raw)
To: Stefan Kangas, Eli Zaretskii; +Cc: contovob, 49316
I have signed the copyright assignment.
Can this be backported to Emacs 28?
On 10/24/21 13:55, Stefan Kangas wrote:
> Eli Zaretskii <eliz@gnu.org> writes:
>
>>> Cc: contovob@tcd.ie, Eli Zaretskii <eliz@gnu.org>
>>> From: daanturo <daanturo@gmail.com>
>>> Date: Fri, 2 Jul 2021 09:49:19 +0700
>>>
>>> I have replaced the examples:
>>>
>>>
>>> (defalias '**2 (apply-rpartially #'expt 2)
>>> "Return argument ** 2.")
>>> (defalias '2** (apply-partially #'expt 2)
>>> "Return 2 ** argument.")
>>> (**2 3)
>>> => 9
>>> (2** 3)
>>> => 8
>> Thanks, the patch LGTM.
> It seems like neither this nor any of the other patches in this bug
> report were applied.
>
> Do we have a copyright assignment for daanturo <daanturo@gmail.com> on
> file?
--
Daanturo.
^ permalink raw reply [flat|nested] 28+ messages in thread
* bug#49316: Add apply-partially's right version
2021-10-24 10:49 ` daanturo
@ 2021-10-24 11:18 ` Stefan Kangas
2021-10-24 12:13 ` Eli Zaretskii
0 siblings, 1 reply; 28+ messages in thread
From: Stefan Kangas @ 2021-10-24 11:18 UTC (permalink / raw)
To: daanturo, Eli Zaretskii; +Cc: contovob, 49316
daanturo <daanturo@gmail.com> writes:
> I have signed the copyright assignment.
Excellent, thanks for clarifying that.
> Can this be backported to Emacs 28?
That's for Eli or Lars to say.
^ permalink raw reply [flat|nested] 28+ messages in thread
* bug#49316: Add apply-partially's right version
2021-10-24 11:18 ` Stefan Kangas
@ 2021-10-24 12:13 ` Eli Zaretskii
2021-10-24 13:47 ` Lars Ingebrigtsen
0 siblings, 1 reply; 28+ messages in thread
From: Eli Zaretskii @ 2021-10-24 12:13 UTC (permalink / raw)
To: Stefan Kangas; +Cc: contovob, daanturo, 49316
> From: Stefan Kangas <stefan@marxist.se>
> Date: Sun, 24 Oct 2021 04:18:13 -0700
> Cc: contovob@tcd.ie, 49316@debbugs.gnu.org
>
> daanturo <daanturo@gmail.com> writes:
>
> > I have signed the copyright assignment.
>
> Excellent, thanks for clarifying that.
>
> > Can this be backported to Emacs 28?
>
> That's for Eli or Lars to say.
It's too late for the release branch.
As for the rest, I'd like Lars to state his opinion about this new
function. AFAICT, he didn't say what he thinks here.
^ permalink raw reply [flat|nested] 28+ messages in thread
* bug#49316: Add apply-partially's right version
2021-10-24 12:13 ` Eli Zaretskii
@ 2021-10-24 13:47 ` Lars Ingebrigtsen
2021-10-24 14:10 ` Stefan Kangas
2021-10-24 14:28 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
0 siblings, 2 replies; 28+ messages in thread
From: Lars Ingebrigtsen @ 2021-10-24 13:47 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: contovob, Stefan Kangas, daanturo, 49316
Eli Zaretskii <eliz@gnu.org> writes:
> As for the rest, I'd like Lars to state his opinion about this new
> function. AFAICT, he didn't say what he thinks here.
I'm not very enthusiastic -- is partial application used a lot now that
we've got lexical binding? Partial application has always seemed like
One Weird Trick to me.
On the other hand -- some people are used to programming using these
idioms, so perhaps it makes sense to add a right version as well?
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 28+ messages in thread
* bug#49316: Add apply-partially's right version
2021-10-24 13:47 ` Lars Ingebrigtsen
@ 2021-10-24 14:10 ` Stefan Kangas
2021-10-24 14:28 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
1 sibling, 0 replies; 28+ messages in thread
From: Stefan Kangas @ 2021-10-24 14:10 UTC (permalink / raw)
To: Lars Ingebrigtsen, Eli Zaretskii
Cc: contovob, daanturo, 49316, Stefan Monnier
Lars Ingebrigtsen <larsi@gnus.org> writes:
> I'm not very enthusiastic -- is partial application used a lot now that
> we've got lexical binding? Partial application has always seemed like
> One Weird Trick to me.
>
> On the other hand -- some people are used to programming using these
> idioms, so perhaps it makes sense to add a right version as well?
I don't think function currying (a.k.a. partial application) is a weird
trick, but I'm also not sure how important it is in Emacs Lisp given
that we prefer writing code in an imperative style. And we can just
create a lambda instead; it is slightly more verbose but also slightly
more familiar.
I've personally missed this a couple of times though, so I definitely
wouldn't mind if it was added.
^ permalink raw reply [flat|nested] 28+ messages in thread
* bug#49316: Add apply-partially's right version
2021-10-24 13:47 ` Lars Ingebrigtsen
2021-10-24 14:10 ` Stefan Kangas
@ 2021-10-24 14:28 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-10-25 12:50 ` Lars Ingebrigtsen
1 sibling, 1 reply; 28+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-10-24 14:28 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: contovob, Eli Zaretskii, Stefan Kangas, daanturo, 49316
Lars Ingebrigtsen [2021-10-24 15:47:00] wrote:
> Eli Zaretskii <eliz@gnu.org> writes:
>> As for the rest, I'd like Lars to state his opinion about this new
>> function. AFAICT, he didn't say what he thinks here.
>
> I'm not very enthusiastic -- is partial application used a lot now that
> we've got lexical binding? Partial application has always seemed like
> One Weird Trick to me.
Like Stefan, I don't find partial application weird.
But I'm not sure what's the advantage of
(apply-rpartially #'foo x y)
over
(lambda (a b) (foo a b x y))
It's not necessarily shorter, it's less flexible (the lambda form lets
you pass args in the middle), and it's less efficient (it necessarily
relies on `&rest`, `append/nconc` and `apply`, which imply allocating
lists).
[ And with prettify-symbols-mode the lambda version is even shorter. ]
> On the other hand -- some people are used to programming using these
> idioms, so perhaps it makes sense to add a right version as well?
`apply-partially` was handy before we had `lexical-binding`, but
I wouldn't have added it to Emacs after Emacs-24.
We already have `dash.el` for those users who like this style.
Stefan
^ permalink raw reply [flat|nested] 28+ messages in thread
* bug#49316: Add apply-partially's right version
2021-10-24 14:28 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2021-10-25 12:50 ` Lars Ingebrigtsen
0 siblings, 0 replies; 28+ messages in thread
From: Lars Ingebrigtsen @ 2021-10-25 12:50 UTC (permalink / raw)
To: Stefan Monnier; +Cc: contovob, Stefan Kangas, daanturo, 49316
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> Like Stefan, I don't find partial application weird.
> But I'm not sure what's the advantage of
>
> (apply-rpartially #'foo x y)
>
> over
>
> (lambda (a b) (foo a b x y))
The advantage is that the first form looks more mysterious and you can
use words like "currying" to sound smarter. :-)
> `apply-partially` was handy before we had `lexical-binding`, but
> I wouldn't have added it to Emacs after Emacs-24.
> We already have `dash.el` for those users who like this style.
I agree. So I think the conclusion here is that we don't want to add
apply-rpartially to Emacs core -- the people that prefer this style will
find more complete coverage in dash.el (which is on GNU ELPA).
So I'm closing this bug report.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 28+ messages in thread
* bug#49316: Add apply-partially's right version
2021-10-24 6:55 ` Stefan Kangas
2021-10-24 10:49 ` daanturo
@ 2021-10-24 13:38 ` Lars Ingebrigtsen
1 sibling, 0 replies; 28+ messages in thread
From: Lars Ingebrigtsen @ 2021-10-24 13:38 UTC (permalink / raw)
To: Stefan Kangas; +Cc: contovob, daanturo, 49316
Stefan Kangas <stefan@marxist.se> writes:
> Do we have a copyright assignment for daanturo <daanturo@gmail.com> on
> file?
Yup.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 28+ messages in thread
* bug#49316: Add apply-partially's right version
2021-07-01 18:45 ` Eli Zaretskii
2021-07-02 2:49 ` daanturo
@ 2021-07-02 16:32 ` daanturo
2021-07-03 7:03 ` Eli Zaretskii
1 sibling, 1 reply; 28+ messages in thread
From: daanturo @ 2021-07-02 16:32 UTC (permalink / raw)
To: 49316
[-- Attachment #1: Type: text/plain, Size: 2485 bytes --]
--=-=-=
Content-Type: text/plain
Tags: patch
Re-write the NEWS entry of apply-rpartially.
--=-=-=
Content-Type: text/patch
Content-Disposition: attachment;
filename=0005-Better-explanation-for-apply-rpartially-in-NEWS.patch
From 339b0ed82dbc0430ce71294f04a53547f532c1af Mon Sep 17 00:00:00 2001
From: Daanturo <daanturo@gmail.com>
Date: Fri, 2 Jul 2021 23:24:37 +0700
Subject: [PATCH] Better explanation for apply-rpartially in NEWS
* etc/NEWS (Lisp Changes in Emacs 28.1): Better explanation for
apply-rpartially
---
etc/NEWS | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/etc/NEWS b/etc/NEWS
index be30d6c859..a06456035c 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2911,8 +2911,8 @@ The former is now declared obsolete.
+++
** New function 'apply-rpartially'.
-Functionally equivalent to 'apply-partially' but arguments are aligned
-to the right instead.
+This is almost similar to 'apply-partially' except that the last
+arguments are fixed instead of first ones.
+++
** New function 'syntax-class-to-char'.
--
2.32.0
--=-=-=--
On 7/2/21 1:45 AM, Eli Zaretskii wrote:
>> From: daanturo <daanturo@gmail.com>
>> Date: Fri, 2 Jul 2021 00:06:35 +0700
>> Cc: "Basil L. Contovounesios" <contovob@tcd.ie>
>>
>> (Please ignore my immediately precededing email, I'm sorry for not being
>> used to sending patches by mailing list.)
> I see no problems in the preceding email, so I think you have nothing
> to apologize for.
>
>> +@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.
> I don't think this explains the purpose of the function clearly
> enough. The documentation of apply-partially doesn't mention any
> "alignment", so it's hard to understand what you want to say here.
> Can you think of a better description?
>
>> +@example
>> +@group
>> +(defalias 'square (apply-rpartially #'expt 2)
>> + "Return argument squared.")
>> +@end group
>> +@group
>> +(square 3)
>> + @result{} 9
>> +@end group
>> +@end example
> IMO, the example could be more revealing if you could contrast
> apply-rpartially with apply-partially.
>
>> ++++
>> +** New function 'apply-rpartially'.
>> +Funcionally equivalent to 'apply-partially' but arguments are aligned
>> +to the right instead.
> After we find a good wording for the manual, we should think how to
> reword the NEWS entry accordingly.
>
> Thanks.
--
Daanturo.
[-- Attachment #2: 0005-Better-explanation-for-apply-rpartially-in-NEWS.patch --]
[-- Type: text/x-patch, Size: 831 bytes --]
From 339b0ed82dbc0430ce71294f04a53547f532c1af Mon Sep 17 00:00:00 2001
From: Daanturo <daanturo@gmail.com>
Date: Fri, 2 Jul 2021 23:24:37 +0700
Subject: [PATCH] Better explanation for apply-rpartially in NEWS
* etc/NEWS (Lisp Changes in Emacs 28.1): Better explanation for
apply-rpartially
---
etc/NEWS | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/etc/NEWS b/etc/NEWS
index be30d6c859..a06456035c 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2911,8 +2911,8 @@ The former is now declared obsolete.
+++
** New function 'apply-rpartially'.
-Functionally equivalent to 'apply-partially' but arguments are aligned
-to the right instead.
+This is almost similar to 'apply-partially' except that the last
+arguments are fixed instead of first ones.
+++
** New function 'syntax-class-to-char'.
--
2.32.0
^ permalink raw reply related [flat|nested] 28+ messages in thread
* bug#49316: Add apply-partially's right version
2021-07-01 12:40 bug#49316: Add apply-partially's right version daanturo
2021-07-01 13:11 ` Basil L. Contovounesios
@ 2021-07-01 22:34 ` Michael Heerdegen
2021-07-02 4:39 ` daanturo
1 sibling, 1 reply; 28+ messages in thread
From: Michael Heerdegen @ 2021-07-01 22:34 UTC (permalink / raw)
To: daanturo; +Cc: 49316
daanturo <daanturo@gmail.com> writes:
| +(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.
I wonder: If we leave syntax aside for a moment - this suggestion seems
to provide a solution for a quite special case: is this useful more
often than partial application of arbitrary arguments? Could we instead
provide something that allows partial application of arbitrary
arguments, e.g. one of the arguments in the middle?
Michael.
^ permalink raw reply [flat|nested] 28+ messages in thread
* bug#49316: Add apply-partially's right version
2021-07-01 22:34 ` Michael Heerdegen
@ 2021-07-02 4:39 ` daanturo
2021-07-03 3:06 ` Michael Heerdegen
0 siblings, 1 reply; 28+ messages in thread
From: daanturo @ 2021-07-02 4:39 UTC (permalink / raw)
To: 49316; +Cc: Michael Heerdegen
[-- Attachment #1.1: Type: text/plain, Size: 3691 bytes --]
--=-=-=
Content-Type: text/plain
Tags: patch
> Could we instead
> provide something that allows partial application of arbitrary
> arguments, e.g. one of the arguments in the middle?
I have tried implementing, but it's really hard to provide a practical
example for documenting.
Also, most of the time after specifying a position, we would insert to
left of that. If 0 is for regular `apply-partially`, then -1 is
certainly not possible for `apply-rpartially`.
To pass ARGS at the last, should the following condition be OK?:
"If POSITION is not an integer or is >= the length of the function
application's arguments in the future."
(funcall (apply-mid-partially #'append 0 '(0 1 2 3)) '(4) '(5)) ;
Equivalent to `apply-partially'`
=> (0 1 2 3 4 5)
(funcall (apply-mid-partially #'append 1 '(1 2 3)) '(0) '(4))
=> (0 1 2 3 4)
(funcall (apply-mid-partially #'append -1 '(1 2 3)) '(-2 -1) '(4 5) '(6 7))
=> (-2 -1 4 5 1 2 3 6 7)
; apply-rpartially
(funcall (apply-mid-partially #'append most-positive-fixnum '(1 2 3))
'(-2 -1) '(4 5) '(6 7))
=> (-2 -1 4 5 6 7 1 2 3)
(funcall (apply-mid-partially #'append 'foo '(1 2 3)) '(-2 -1) '(4 5)
'(6 7))
=> (-2 -1 4 5 6 7 1 2 3)
--=-=-=
Content-Type: text/patch
Content-Disposition: attachment;
filename=0005-b-Define-apply-mid-partially.patch
From 88522f33b497a6463ee73c4ba9479e853291035a Mon Sep 17 00:00:00 2001
From: Daanturo <daanturo@gmail.com>
Date: Fri, 2 Jul 2021 11:22:11 +0700
Subject: [PATCH] Define apply-mid-partially
* lisp/subr.el (apply-mid-partially): Currying functions with arbitrary
arguments position.
---
lisp/subr.el | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/lisp/subr.el b/lisp/subr.el
index 5965655d48..2c25343a76 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -474,6 +474,33 @@ function was called."
(lambda (&rest args1)
(apply fun (append args1 args))))
+(defun apply-mid-partially (fun position &rest args)
+ "Return a function that is a partial application of FUN to ARGS at
POSITION.
+
+ARGS is a list of N arguments to pass to FUN, starting at
+POSITION (integer).
+
+The result is a new function which does the same as FUN, except
+that N arguments starting from POSITION (inclusive) are fixed at the
+values with which this function was called.
+
+If POSITION is not an integer or is >= the length of the function
+application's arguments in the future, ARGS will be at the last.
+
+Else if POSITION is non-negative integer, count from the left.
+
+Else (POSITION is a negative integer), count from the right."
+ (lambda (&rest other-args)
+ (let* ((right-partially (or (not (integerp position))
+ (<= (length other-args) position)))
+ (first-args (seq-subseq other-args
+ 0
+ (if right-partially nil position)))
+ (last-args (if right-partially
+ nil
+ (seq-subseq other-args position))))
+ (apply fun (append first-args args last-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
--=-=-=--
On 7/2/21 5:34 AM, Michael Heerdegen wrote:
> daanturo <daanturo@gmail.com> writes:
>
> | +(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.
>
> I wonder: If we leave syntax aside for a moment - this suggestion seems
> to provide a solution for a quite special case: is this useful more
> often than partial application of arbitrary arguments? Could we instead
> provide something that allows partial application of arbitrary
> arguments, e.g. one of the arguments in the middle?
>
>
> Michael.
--
Daanturo.
[-- Attachment #1.2: Type: text/html, Size: 6000 bytes --]
[-- Attachment #2: 0005-b-Define-apply-mid-partially.patch --]
[-- Type: text/x-patch, Size: 1913 bytes --]
From 88522f33b497a6463ee73c4ba9479e853291035a Mon Sep 17 00:00:00 2001
From: Daanturo <daanturo@gmail.com>
Date: Fri, 2 Jul 2021 11:22:11 +0700
Subject: [PATCH] Define apply-mid-partially
* lisp/subr.el (apply-mid-partially): Currying functions with arbitrary
arguments position.
---
lisp/subr.el | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/lisp/subr.el b/lisp/subr.el
index 5965655d48..2c25343a76 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -474,6 +474,33 @@ function was called."
(lambda (&rest args1)
(apply fun (append args1 args))))
+(defun apply-mid-partially (fun position &rest args)
+ "Return a function that is a partial application of FUN to ARGS at POSITION.
+
+ARGS is a list of N arguments to pass to FUN, starting at
+POSITION (integer).
+
+The result is a new function which does the same as FUN, except
+that N arguments starting from POSITION (inclusive) are fixed at the
+values with which this function was called.
+
+If POSITION is not an integer or is >= the length of the function
+application's arguments in the future, ARGS will be at the last.
+
+Else if POSITION is non-negative integer, count from the left.
+
+Else (POSITION is a negative integer), count from the right."
+ (lambda (&rest other-args)
+ (let* ((right-partially (or (not (integerp position))
+ (<= (length other-args) position)))
+ (first-args (seq-subseq other-args
+ 0
+ (if right-partially nil position)))
+ (last-args (if right-partially
+ nil
+ (seq-subseq other-args position))))
+ (apply fun (append first-args args last-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
^ permalink raw reply related [flat|nested] 28+ messages in thread
* bug#49316: Add apply-partially's right version
2021-07-02 4:39 ` daanturo
@ 2021-07-03 3:06 ` Michael Heerdegen
2021-07-03 6:17 ` daanturo
2021-07-03 14:13 ` Phil Sainty
0 siblings, 2 replies; 28+ messages in thread
From: Michael Heerdegen @ 2021-07-03 3:06 UTC (permalink / raw)
To: daanturo; +Cc: 49316
daanturo <daanturo@gmail.com> writes:
> +(defun apply-mid-partially (fun position &rest args)
> + "Return a function that is a partial application of FUN to ARGS at POSITION.
I'm not sure if I would prefer that. Personally I guess I would like
something like this instead: A macro that allows partial application
that really looks like an application.
A placeholder (e.g. the symbol `_' which should normally be unbound)
stands for an argument that is used from the args provided in the actual
call:
#+begin_src emacs-lisp
(defmacro applying-partially (call)
(let ((args (make-symbol "args")))
`(lambda (&rest ,args)
(apply #',(car call)
,@(mapcar (lambda (arg)
(if (eq arg '_)
`(pop ,args)
arg))
(cdr call))
,args))))
(defalias 'minus-10 (applying-partially (- _ 10)))
(minus-10 120) ;; ==> 110
(defalias 'my-list-with-some-elts
(applying-partially (list 0 _ 2 _ 4)))
(my-list-with-some-elts 'a 'b 'c 'd) ; => (0 a 2 b 4 c d)
(symbol-function 'my-list-with-some-elts)
;; => (closure (t) (&rest args)
;; (apply #'list 0 (pop args) 2 (pop args) 4 args))
#+end_src
In my eyes that would be more general and a bit better readable (I like
when eldoc works with such stuff).
Regards,
Michael.
^ permalink raw reply [flat|nested] 28+ messages in thread
* bug#49316: Add apply-partially's right version
2021-07-03 3:06 ` Michael Heerdegen
@ 2021-07-03 6:17 ` daanturo
2021-07-03 14:13 ` Phil Sainty
1 sibling, 0 replies; 28+ messages in thread
From: daanturo @ 2021-07-03 6:17 UTC (permalink / raw)
To: Michael Heerdegen; +Cc: 49316
That's cool! Can you submit the patch?
On 7/3/21 10:06 AM, Michael Heerdegen wrote:
> A placeholder (e.g. the symbol `_' which should normally be unbound)
> stands for an argument that is used from the args provided in the actual
> call:
>
> #+begin_src emacs-lisp
> (defmacro applying-partially (call)
> (let ((args (make-symbol "args")))
> `(lambda (&rest ,args)
> (apply #',(car call)
> ,@(mapcar (lambda (arg)
> (if (eq arg '_)
> `(pop ,args)
> arg))
> (cdr call))
> ,args))))
>
> (defalias 'minus-10 (applying-partially (- _ 10)))
>
> (minus-10 120) ;; ==> 110
>
> (defalias 'my-list-with-some-elts
> (applying-partially (list 0 _ 2 _ 4)))
>
> (my-list-with-some-elts 'a 'b 'c 'd) ; => (0 a 2 b 4 c d)
>
> (symbol-function 'my-list-with-some-elts)
> ;; => (closure (t) (&rest args)
> ;; (apply #'list 0 (pop args) 2 (pop args) 4 args))
> #+end_src
>
> --
> Daanturo.
^ permalink raw reply [flat|nested] 28+ messages in thread
* bug#49316: Add apply-partially's right version
2021-07-03 3:06 ` Michael Heerdegen
2021-07-03 6:17 ` daanturo
@ 2021-07-03 14:13 ` Phil Sainty
2021-07-05 4:29 ` daanturo
1 sibling, 1 reply; 28+ messages in thread
From: Phil Sainty @ 2021-07-03 14:13 UTC (permalink / raw)
To: Michael Heerdegen; +Cc: daanturo, 49316
On 2021-07-03 15:06, Michael Heerdegen wrote:
> A placeholder (e.g. the symbol `_' which should normally be unbound)
> stands for an argument that is used from the args provided in the
> actual
> call:
>
> (defalias 'my-list-with-some-elts
> (applying-partially (list 0 _ 2 _ 4)))
>
> (my-list-with-some-elts 'a 'b 'c 'd) ; => (0 a 2 b 4 c d)
I like the flexibility of the placeholder approach. I'm not
sold on the extra parens used here -- I don't feel too strongly
about it, but it's inconsistent with how `apply-partially' is
called.
Similarly, being a macro is inconsistent, and eliminates the
ability to apply an arbitrary list of arguments to this, which
may be a useful thing to be able to do. (It's syntactic sugar
though, so we don't *need* to account for all scenarios --
other use-cases can use the same approaches they do now.)
It's slightly problematic that any chosen placeholder might
be a valid argument to the function in question. An underscore
feels as good a choice as any other, though, and provides the
mental association with the conventional use of an underscore
for unused arguments. I suppose this issue is partly mitigated
if it does end up being a macro, as we can't then apply some
unknown list of args (which might happen to include the
placeholder value).
I think this is useful enough to implement regardless of that
last issue, and it could simply be documented that it shouldn't
be used in cases where the arguments are unknown, or where an
underscore (or whatever placeholder is chosen) is a valid arg.
-Phil
^ permalink raw reply [flat|nested] 28+ messages in thread
* bug#49316: Add apply-partially's right version
2021-07-03 14:13 ` Phil Sainty
@ 2021-07-05 4:29 ` daanturo
2021-07-05 12:02 ` Phil Sainty
2021-07-06 4:33 ` Michael Heerdegen
0 siblings, 2 replies; 28+ messages in thread
From: daanturo @ 2021-07-05 4:29 UTC (permalink / raw)
To: Phil Sainty, Michael Heerdegen; +Cc: 49316
On 7/3/21 9:13 PM, Phil Sainty wrote:
> On 2021-07-03 15:06, Michael Heerdegen wrote:
>> A placeholder (e.g. the symbol `_' which should normally be unbound)
>> stands for an argument that is used from the args provided in the actual
>> call:
>>
>> (defalias 'my-list-with-some-elts
>> (applying-partially (list 0 _ 2 _ 4)))
>>
>> (my-list-with-some-elts 'a 'b 'c 'd) ; => (0 a 2 b 4 c d)
>
> I like the flexibility of the placeholder approach. I'm not
> sold on the extra parens used here -- I don't feel too strongly
> about it, but it's inconsistent with how `apply-partially' is
> called.
The author has mentioned that the reason for being a macro with extra
parentheses was the ability to work with `eldoc`: inside the inner pair of
parentheses, we can look at parameters suggestion which is normally not
possible
with `apply-partially`.
`applying-partially` is bit confusing given the name of the existing
function.
To differentiate it, can we name this macro differently? Like
`any-partial-application`, `partially-apply-at_`, etc.
--
Daanturo.
^ permalink raw reply [flat|nested] 28+ messages in thread
* bug#49316: Add apply-partially's right version
2021-07-05 4:29 ` daanturo
@ 2021-07-05 12:02 ` Phil Sainty
2021-07-06 4:33 ` Michael Heerdegen
1 sibling, 0 replies; 28+ messages in thread
From: Phil Sainty @ 2021-07-05 12:02 UTC (permalink / raw)
To: daanturo; +Cc: Michael Heerdegen, 49316
On 2021-07-05 16:29, daanturo wrote:
> The author has mentioned that the reason for being a macro with extra
> parentheses was the ability to work with `eldoc`: inside the inner pair
> of parentheses, we can look at parameters suggestion which is normally
> not possible with `apply-partially`.
Thanks, I missed that. That makes sense.
> `applying-partially` is bit confusing given the name of the existing
> function.
I agree, although I've failed to think of any alternative names that I
think are good.
-Phil
^ permalink raw reply [flat|nested] 28+ messages in thread
* bug#49316: Add apply-partially's right version
2021-07-05 4:29 ` daanturo
2021-07-05 12:02 ` Phil Sainty
@ 2021-07-06 4:33 ` Michael Heerdegen
2021-07-07 16:30 ` daanturo
1 sibling, 1 reply; 28+ messages in thread
From: Michael Heerdegen @ 2021-07-06 4:33 UTC (permalink / raw)
To: daanturo; +Cc: Phil Sainty, 49316
daanturo <daanturo@gmail.com> writes:
> The author has mentioned that the reason for being a macro with extra
> parentheses was the ability to work with `eldoc`: inside the inner pair of
> parentheses, we can look at parameters suggestion which is normally
> not possible
> with `apply-partially`.
>
> `applying-partially` is bit confusing given the name of the existing
> function.
> To differentiate it, can we name this macro differently? Like
> `any-partial-application`, `partially-apply-at_`, etc.
I don't insist on the name, I used just some random different name.
There are several advantages of a macro here: the parameters can be
processed at compile-time, generating slightly nicer code. And the
programmer doesn't need to quote the _ symbol.
But I agree that a function version would make sense, too.
Michael.
^ permalink raw reply [flat|nested] 28+ messages in thread
end of thread, other threads:[~2021-10-25 12:50 UTC | newest]
Thread overview: 28+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-07-01 12:40 bug#49316: Add apply-partially's right version daanturo
2021-07-01 13:11 ` Basil L. Contovounesios
2021-07-01 16:24 ` daanturo
2021-07-01 17:06 ` daanturo
2021-07-01 17:16 ` daanturo
2021-07-01 18:45 ` Eli Zaretskii
2021-07-02 2:49 ` daanturo
2021-07-03 7:03 ` Eli Zaretskii
2021-10-24 6:55 ` Stefan Kangas
2021-10-24 10:49 ` daanturo
2021-10-24 11:18 ` Stefan Kangas
2021-10-24 12:13 ` Eli Zaretskii
2021-10-24 13:47 ` Lars Ingebrigtsen
2021-10-24 14:10 ` Stefan Kangas
2021-10-24 14:28 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-10-25 12:50 ` Lars Ingebrigtsen
2021-10-24 13:38 ` Lars Ingebrigtsen
2021-07-02 16:32 ` daanturo
2021-07-03 7:03 ` Eli Zaretskii
2021-07-01 22:34 ` Michael Heerdegen
2021-07-02 4:39 ` daanturo
2021-07-03 3:06 ` Michael Heerdegen
2021-07-03 6:17 ` daanturo
2021-07-03 14:13 ` Phil Sainty
2021-07-05 4:29 ` daanturo
2021-07-05 12:02 ` Phil Sainty
2021-07-06 4:33 ` Michael Heerdegen
2021-07-07 16:30 ` daanturo
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.