GNU bug report logs - #49316
Add apply-partially's right version

Previous Next

Package: emacs;

Reported by: daanturo <daanturo <at> gmail.com>

Date: Thu, 1 Jul 2021 12:41:02 UTC

Severity: normal

Tags: patch, wontfix

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 49316 in the body.
You can then email your comments to 49316 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#49316; Package emacs. (Thu, 01 Jul 2021 12:41:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to daanturo <daanturo <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Thu, 01 Jul 2021 12:41:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: daanturo <daanturo <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: Add apply-partially's right version
Date: Thu, 1 Jul 2021 19:40:20 +0700
[Message part 1 (text/plain, inline)]
--=-=-=
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 <at> 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.

[0001-Define-apply-rpatially.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49316; Package emacs. (Thu, 01 Jul 2021 13:13:02 GMT) Full text and rfc822 format available.

Message #8 received at 49316 <at> debbugs.gnu.org (full text, mbox):

From: "Basil L. Contovounesios" <contovob <at> tcd.ie>
To: daanturo <daanturo <at> gmail.com>
Cc: 49316 <at> debbugs.gnu.org
Subject: Re: bug#49316: Add apply-partially's right version
Date: Thu, 01 Jul 2021 14:11:55 +0100
tags 49316 + patch
quit

> From c594d6fc396b80019c48e63918f8c5e485f2782f Mon Sep 17 00:00:00 2001
> From: Daanturo <daanturo <at> 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




Added tag(s) patch. Request was from "Basil L. Contovounesios" <contovob <at> tcd.ie> to control <at> debbugs.gnu.org. (Thu, 01 Jul 2021 13:13:03 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49316; Package emacs. (Thu, 01 Jul 2021 16:25:01 GMT) Full text and rfc822 format available.

Message #13 received at 49316 <at> debbugs.gnu.org (full text, mbox):

From: daanturo <daanturo <at> gmail.com>
To: 49316 <at> debbugs.gnu.org
Cc: "Basil L. Contovounesios" <contovob <at> tcd.ie>
Subject: Re: bug#49316: Add apply-partially's right version
Date: Thu, 1 Jul 2021 23:24:22 +0700
[Message part 1 (text/plain, inline)]
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 <at> 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.

[0002-Add-apply-rpartially-documents.patch (text/x-patch, attachment)]
[0001-Define-apply-rpartially.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49316; Package emacs. (Thu, 01 Jul 2021 17:07:01 GMT) Full text and rfc822 format available.

Message #16 received at 49316 <at> debbugs.gnu.org (full text, mbox):

From: daanturo <daanturo <at> gmail.com>
To: 49316 <at> debbugs.gnu.org
Cc: "Basil L. Contovounesios" <contovob <at> tcd.ie>
Subject: Re: bug#49316: Add apply-partially's right version
Date: Fri, 2 Jul 2021 00:06:35 +0700
[Message part 1 (text/plain, inline)]
--=-=-=
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 <at> 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.

* 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.

[0002-Add-apply-rpartially-documents.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49316; Package emacs. (Thu, 01 Jul 2021 17:17:02 GMT) Full text and rfc822 format available.

Message #19 received at 49316 <at> debbugs.gnu.org (full text, mbox):

From: daanturo <daanturo <at> gmail.com>
To: 49316 <at> debbugs.gnu.org
Cc: "Basil L. Contovounesios" <contovob <at> tcd.ie>
Subject: Re: bug#49316: Add apply-partially's right version
Date: Fri, 2 Jul 2021 00:16:48 +0700
[Message part 1 (text/plain, inline)]
--=-=-=
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 <at> 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.

[0001-Fix-apply-rpartially-s-typo-in-etc-NEWS.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49316; Package emacs. (Thu, 01 Jul 2021 18:46:02 GMT) Full text and rfc822 format available.

Message #22 received at 49316 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: daanturo <daanturo <at> gmail.com>
Cc: contovob <at> tcd.ie, 49316 <at> debbugs.gnu.org
Subject: Re: bug#49316: Add apply-partially's right version
Date: Thu, 01 Jul 2021 21:45:15 +0300
> From: daanturo <daanturo <at> gmail.com>
> Date: Fri, 2 Jul 2021 00:06:35 +0700
> Cc: "Basil L. Contovounesios" <contovob <at> 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.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49316; Package emacs. (Thu, 01 Jul 2021 22:35:01 GMT) Full text and rfc822 format available.

Message #25 received at 49316 <at> debbugs.gnu.org (full text, mbox):

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: daanturo <daanturo <at> gmail.com>
Cc: 49316 <at> debbugs.gnu.org
Subject: Re: bug#49316: Add apply-partially's right version
Date: Fri, 02 Jul 2021 00:34:34 +0200
daanturo <daanturo <at> 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.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49316; Package emacs. (Fri, 02 Jul 2021 02:50:01 GMT) Full text and rfc822 format available.

Message #28 received at 49316 <at> debbugs.gnu.org (full text, mbox):

From: daanturo <daanturo <at> gmail.com>
To: 49316 <at> debbugs.gnu.org
Cc: contovob <at> tcd.ie, Eli Zaretskii <eliz <at> gnu.org>
Subject: Re: bug#49316: Add apply-partially's right version
Date: Fri, 2 Jul 2021 09:49:19 +0700
[Message part 1 (text/plain, inline)]
--=-=-=
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 <at> 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 <at> gmail.com>
>> Date: Fri, 2 Jul 2021 00:06:35 +0700
>> Cc: "Basil L. Contovounesios" <contovob <at> 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.

[0004-Better-apply-rpartially-documentation.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49316; Package emacs. (Fri, 02 Jul 2021 04:40:02 GMT) Full text and rfc822 format available.

Message #31 received at 49316 <at> debbugs.gnu.org (full text, mbox):

From: daanturo <daanturo <at> gmail.com>
To: 49316 <at> debbugs.gnu.org
Cc: Michael Heerdegen <michael_heerdegen <at> web.de>
Subject: Re: bug#49316: Add apply-partially's right version
Date: Fri, 2 Jul 2021 11:39:03 +0700
[Message part 1 (text/plain, inline)]
--=-=-=
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 <at> 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 <at> 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.

[Message part 2 (text/html, inline)]
[0005-b-Define-apply-mid-partially.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49316; Package emacs. (Fri, 02 Jul 2021 16:33:01 GMT) Full text and rfc822 format available.

Message #34 received at 49316 <at> debbugs.gnu.org (full text, mbox):

From: daanturo <daanturo <at> gmail.com>
To: 49316 <at> debbugs.gnu.org
Cc: Eli Zaretskii <eliz <at> gnu.org>
Subject: Re: bug#49316: Add apply-partially's right version
Date: Fri, 2 Jul 2021 23:32:25 +0700
[Message part 1 (text/plain, inline)]
--=-=-=
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 <at> 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 <at> gmail.com>
>> Date: Fri, 2 Jul 2021 00:06:35 +0700
>> Cc: "Basil L. Contovounesios" <contovob <at> 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.

[0005-Better-explanation-for-apply-rpartially-in-NEWS.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49316; Package emacs. (Sat, 03 Jul 2021 03:07:02 GMT) Full text and rfc822 format available.

Message #37 received at 49316 <at> debbugs.gnu.org (full text, mbox):

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: daanturo <daanturo <at> gmail.com>
Cc: 49316 <at> debbugs.gnu.org
Subject: Re: bug#49316: Add apply-partially's right version
Date: Sat, 03 Jul 2021 05:06:18 +0200
daanturo <daanturo <at> 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.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49316; Package emacs. (Sat, 03 Jul 2021 06:19:02 GMT) Full text and rfc822 format available.

Message #40 received at 49316 <at> debbugs.gnu.org (full text, mbox):

From: daanturo <daanturo <at> gmail.com>
To: Michael Heerdegen <michael_heerdegen <at> web.de>
Cc: 49316 <at> debbugs.gnu.org
Subject: Re: bug#49316: Add apply-partially's right version
Date: Sat, 3 Jul 2021 13:17:50 +0700
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.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49316; Package emacs. (Sat, 03 Jul 2021 07:04:01 GMT) Full text and rfc822 format available.

Message #43 received at 49316 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: daanturo <daanturo <at> gmail.com>
Cc: 49316 <at> debbugs.gnu.org
Subject: Re: bug#49316: Add apply-partially's right version
Date: Sat, 03 Jul 2021 10:03:15 +0300
> Cc: Eli Zaretskii <eliz <at> gnu.org>
> From: daanturo <daanturo <at> gmail.com>
> Date: Fri, 2 Jul 2021 23:32:25 +0700
> 
> Re-write the NEWS entry of apply-rpartially.

This LGTM, thanks.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49316; Package emacs. (Sat, 03 Jul 2021 07:05:02 GMT) Full text and rfc822 format available.

Message #46 received at 49316 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: daanturo <daanturo <at> gmail.com>
Cc: contovob <at> tcd.ie, 49316 <at> debbugs.gnu.org
Subject: Re: bug#49316: Add apply-partially's right version
Date: Sat, 03 Jul 2021 10:03:58 +0300
> Cc: contovob <at> tcd.ie, Eli Zaretskii <eliz <at> gnu.org>
> From: daanturo <daanturo <at> 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.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49316; Package emacs. (Sat, 03 Jul 2021 14:15:02 GMT) Full text and rfc822 format available.

Message #49 received at 49316 <at> debbugs.gnu.org (full text, mbox):

From: Phil Sainty <psainty <at> orcon.net.nz>
To: Michael Heerdegen <michael_heerdegen <at> web.de>
Cc: daanturo <daanturo <at> gmail.com>, 49316 <at> debbugs.gnu.org
Subject: Re: bug#49316: Add apply-partially's right version
Date: Sun, 04 Jul 2021 02:13:53 +1200
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





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49316; Package emacs. (Mon, 05 Jul 2021 04:30:02 GMT) Full text and rfc822 format available.

Message #52 received at 49316 <at> debbugs.gnu.org (full text, mbox):

From: daanturo <daanturo <at> gmail.com>
To: Phil Sainty <psainty <at> orcon.net.nz>,
 Michael Heerdegen <michael_heerdegen <at> web.de>
Cc: 49316 <at> debbugs.gnu.org
Subject: Re: bug#49316: Add apply-partially's right version
Date: Mon, 5 Jul 2021 11:29:15 +0700
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.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49316; Package emacs. (Mon, 05 Jul 2021 12:03:02 GMT) Full text and rfc822 format available.

Message #55 received at 49316 <at> debbugs.gnu.org (full text, mbox):

From: Phil Sainty <psainty <at> orcon.net.nz>
To: daanturo <daanturo <at> gmail.com>
Cc: Michael Heerdegen <michael_heerdegen <at> web.de>, 49316 <at> debbugs.gnu.org
Subject: Re: bug#49316: Add apply-partially's right version
Date: Tue, 06 Jul 2021 00:02:31 +1200
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





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49316; Package emacs. (Tue, 06 Jul 2021 04:34:01 GMT) Full text and rfc822 format available.

Message #58 received at 49316 <at> debbugs.gnu.org (full text, mbox):

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: daanturo <daanturo <at> gmail.com>
Cc: Phil Sainty <psainty <at> orcon.net.nz>, 49316 <at> debbugs.gnu.org
Subject: Re: bug#49316: Add apply-partially's right version
Date: Tue, 06 Jul 2021 06:33:04 +0200
daanturo <daanturo <at> 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.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49316; Package emacs. (Wed, 07 Jul 2021 16:32:02 GMT) Full text and rfc822 format available.

Message #61 received at 49316 <at> debbugs.gnu.org (full text, mbox):

From: daanturo <daanturo <at> gmail.com>
To: Michael Heerdegen <michael_heerdegen <at> web.de>
Cc: 49316 <at> debbugs.gnu.org
Subject: Re: bug#49316: Add apply-partially's right version
Date: Wed, 7 Jul 2021 23:30:51 +0700
On 7/6/21 11:33 AM, Michael Heerdegen wrote:
> I don't insist on the name, I used just some random different name.
Apparently the macro you haved proposed is named `cut` in Scheme (although
without inner parameters):
https://www.gnu.org/software/guile/manual/html_node/SRFI_002d26.html

And `-cut` in dash.el.

-- 
Daanturo.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49316; Package emacs. (Sun, 24 Oct 2021 06:56:02 GMT) Full text and rfc822 format available.

Message #64 received at 49316 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefan <at> marxist.se>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: contovob <at> tcd.ie, daanturo <daanturo <at> gmail.com>, 49316 <at> debbugs.gnu.org
Subject: Re: bug#49316: Add apply-partially's right version
Date: Sat, 23 Oct 2021 23:55:04 -0700
Eli Zaretskii <eliz <at> gnu.org> writes:

>> Cc: contovob <at> tcd.ie, Eli Zaretskii <eliz <at> gnu.org>
>> From: daanturo <daanturo <at> 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 <at> gmail.com> on
file?

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49316; Package emacs. (Sun, 24 Oct 2021 10:52:01 GMT) Full text and rfc822 format available.

Message #67 received at 49316 <at> debbugs.gnu.org (full text, mbox):

From: daanturo <daanturo <at> gmail.com>
To: Stefan Kangas <stefan <at> marxist.se>, Eli Zaretskii <eliz <at> gnu.org>
Cc: contovob <at> tcd.ie, 49316 <at> debbugs.gnu.org
Subject: Re: bug#49316: Add apply-partially's right version
Date: Sun, 24 Oct 2021 17:49:29 +0700
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 <at> gnu.org> writes:
>
>>> Cc: contovob <at> tcd.ie, Eli Zaretskii <eliz <at> gnu.org>
>>> From: daanturo <daanturo <at> 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 <at> gmail.com> on
> file?

-- 
Daanturo.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49316; Package emacs. (Sun, 24 Oct 2021 11:19:02 GMT) Full text and rfc822 format available.

Message #70 received at 49316 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefan <at> marxist.se>
To: daanturo <daanturo <at> gmail.com>, Eli Zaretskii <eliz <at> gnu.org>
Cc: contovob <at> tcd.ie, 49316 <at> debbugs.gnu.org
Subject: Re: bug#49316: Add apply-partially's right version
Date: Sun, 24 Oct 2021 04:18:13 -0700
daanturo <daanturo <at> 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.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49316; Package emacs. (Sun, 24 Oct 2021 12:15:01 GMT) Full text and rfc822 format available.

Message #73 received at 49316 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Stefan Kangas <stefan <at> marxist.se>
Cc: contovob <at> tcd.ie, daanturo <at> gmail.com, 49316 <at> debbugs.gnu.org
Subject: Re: bug#49316: Add apply-partially's right version
Date: Sun, 24 Oct 2021 15:13:44 +0300
> From: Stefan Kangas <stefan <at> marxist.se>
> Date: Sun, 24 Oct 2021 04:18:13 -0700
> Cc: contovob <at> tcd.ie, 49316 <at> debbugs.gnu.org
> 
> daanturo <daanturo <at> 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.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49316; Package emacs. (Sun, 24 Oct 2021 13:39:02 GMT) Full text and rfc822 format available.

Message #76 received at 49316 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Stefan Kangas <stefan <at> marxist.se>
Cc: contovob <at> tcd.ie, Eli Zaretskii <eliz <at> gnu.org>,
 daanturo <daanturo <at> gmail.com>, 49316 <at> debbugs.gnu.org
Subject: Re: bug#49316: Add apply-partially's right version
Date: Sun, 24 Oct 2021 15:38:40 +0200
Stefan Kangas <stefan <at> marxist.se> writes:

> Do we have a copyright assignment for daanturo <daanturo <at> gmail.com> on
> file?

Yup.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49316; Package emacs. (Sun, 24 Oct 2021 13:48:02 GMT) Full text and rfc822 format available.

Message #79 received at 49316 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: contovob <at> tcd.ie, Stefan Kangas <stefan <at> marxist.se>, daanturo <at> gmail.com,
 49316 <at> debbugs.gnu.org
Subject: Re: bug#49316: Add apply-partially's right version
Date: Sun, 24 Oct 2021 15:47:00 +0200
Eli Zaretskii <eliz <at> 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




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49316; Package emacs. (Sun, 24 Oct 2021 14:11:01 GMT) Full text and rfc822 format available.

Message #82 received at 49316 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefan <at> marxist.se>
To: Lars Ingebrigtsen <larsi <at> gnus.org>, Eli Zaretskii <eliz <at> gnu.org>
Cc: contovob <at> tcd.ie, daanturo <at> gmail.com, 49316 <at> debbugs.gnu.org,
 Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#49316: Add apply-partially's right version
Date: Sun, 24 Oct 2021 07:10:36 -0700
Lars Ingebrigtsen <larsi <at> 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.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49316; Package emacs. (Sun, 24 Oct 2021 14:29:02 GMT) Full text and rfc822 format available.

Message #85 received at 49316 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: contovob <at> tcd.ie, Eli Zaretskii <eliz <at> gnu.org>,
 Stefan Kangas <stefan <at> marxist.se>, daanturo <at> gmail.com, 49316 <at> debbugs.gnu.org
Subject: Re: bug#49316: Add apply-partially's right version
Date: Sun, 24 Oct 2021 10:28:14 -0400
Lars Ingebrigtsen [2021-10-24 15:47:00] wrote:
> Eli Zaretskii <eliz <at> 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





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49316; Package emacs. (Mon, 25 Oct 2021 12:52:02 GMT) Full text and rfc822 format available.

Message #88 received at 49316 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: contovob <at> tcd.ie, Eli Zaretskii <eliz <at> gnu.org>,
 Stefan Kangas <stefan <at> marxist.se>, daanturo <at> gmail.com, 49316 <at> debbugs.gnu.org
Subject: Re: bug#49316: Add apply-partially's right version
Date: Mon, 25 Oct 2021 14:50:57 +0200
Stefan Monnier <monnier <at> 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




Added tag(s) wontfix. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Mon, 25 Oct 2021 12:52:02 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 49316 <at> debbugs.gnu.org and daanturo <daanturo <at> gmail.com> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Mon, 25 Oct 2021 12:52:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 23 Nov 2021 12:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 147 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.