unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* What's up with apply-partially?
@ 2015-01-23 22:14 David Kastrup
  2015-01-24  3:05 ` Leo Liu
  2015-01-24  3:53 ` What's up with apply-partially? Artur Malabarba
  0 siblings, 2 replies; 11+ messages in thread
From: David Kastrup @ 2015-01-23 22:14 UTC (permalink / raw)
  To: emacs-devel


The original definition of apply-partially in subr.el by Eli in 2008 has
been

(defun apply-partially (fun &rest args)
  "Return a function that is a partial application of FUN to ARGS.
ARGS is a list of the first N arguments to pass to FUN.
The result is a new function which does the same as FUN, except that
the first N arguments are fixed at the values with which this function
was called."
  (lexical-let ((fun fun) (args1 args))
    (lambda (&rest args2) (apply fun (append args1 args2)))))

The current definition by Stefan, however, is
(defun apply-partially (fun &rest args)
  "Return a function that is a partial application of FUN to ARGS.
ARGS is a list of the first N arguments to pass to FUN.
The result is a new function which does the same as FUN, except that
the first N arguments are fixed at the values with which this function
was called."
  `(closure (t) (&rest args)
            (apply ',fun ,@(mapcar (lambda (arg) `',arg) args) args)))

Now subr.el has lexical-bind set.  It seems quite pointless to return
some unevaluated quoted list here (apply-partially is not a macro but a
function!).

So why not just

(defun apply-partially (fun &rest args)
  (lambda (&rest args2) (apply fun (append args args2))))

Where is the point in the complicated redefinition that returns a
basically uncompiled function?  Why not just take Eli's definition and
simplify it in line with lexical-binding now being set?

I don't understand the point of the change.  Lexical bindings should
have made this function more straightforward.  Instead it has become
more complex and unevaluated.  And it's not like describe-function even
knows `closure', as opposed to `lambda'.  So it's become inscrutable as
well.

-- 
David Kastrup



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: What's up with apply-partially?
  2015-01-23 22:14 What's up with apply-partially? David Kastrup
@ 2015-01-24  3:05 ` Leo Liu
  2015-01-24  5:01   ` Stefan Monnier
  2015-01-24  3:53 ` What's up with apply-partially? Artur Malabarba
  1 sibling, 1 reply; 11+ messages in thread
From: Leo Liu @ 2015-01-24  3:05 UTC (permalink / raw)
  To: David Kastrup; +Cc: emacs-devel

On 2015-01-24 06:14 +0800, David Kastrup wrote:
>   `(closure (t) (&rest args)
>             (apply ',fun ,@(mapcar (lambda (arg) `',arg) args) args)))

I have been wondering this myself. I wonder if it was a workaround from
the time when lexical-binding is not activated in subr.el?

The implementation does away `append' and is specially handled in
cconv-convert so it might actually be more efficient but I am just
wondering ;)

Leo



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: What's up with apply-partially?
  2015-01-23 22:14 What's up with apply-partially? David Kastrup
  2015-01-24  3:05 ` Leo Liu
@ 2015-01-24  3:53 ` Artur Malabarba
  1 sibling, 0 replies; 11+ messages in thread
From: Artur Malabarba @ 2015-01-24  3:53 UTC (permalink / raw)
  To: David Kastrup; +Cc: emacs-devel

> So why not just
>
> (defun apply-partially (fun &rest args)
>   (lambda (&rest args2) (apply fun (append args args2))))
>
> Where is the point in the complicated redefinition that returns a
> basically uncompiled function?  Why not just take Eli's definition and
> simplify it in line with lexical-binding now being set?

As Leo mentioned, the current definition creates the argument list
when `apply-partially' is first called, whereas your suggestion has to
call `append' everytime the returned function is called.

I think that's the only reason. It's unclear to me how that
performance difference compares with the disadvantage of the returned
function not being compiled.



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: What's up with apply-partially?
  2015-01-24  3:05 ` Leo Liu
@ 2015-01-24  5:01   ` Stefan Monnier
  2015-01-24  8:54     ` David Kastrup
  0 siblings, 1 reply; 11+ messages in thread
From: Stefan Monnier @ 2015-01-24  5:01 UTC (permalink / raw)
  To: Leo Liu; +Cc: David Kastrup, emacs-devel

> I have been wondering this myself. I wonder if it was a workaround from
> the time when lexical-binding was not activated in subr.el?

Yes, I think this is the explanation.  Feel free to change it,


        Stefan



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: What's up with apply-partially?
  2015-01-24  5:01   ` Stefan Monnier
@ 2015-01-24  8:54     ` David Kastrup
  2015-01-25 14:32       ` Stefan Monnier
  0 siblings, 1 reply; 11+ messages in thread
From: David Kastrup @ 2015-01-24  8:54 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Leo Liu, emacs-devel

Stefan Monnier <monnier@IRO.UMontreal.CA> writes:

>> I have been wondering this myself. I wonder if it was a workaround from
>> the time when lexical-binding was not activated in subr.el?
>
> Yes, I think this is the explanation.  Feel free to change it,

Huh.  Perhaps this causes different behavior depending on whether the
_use_ of apply-partially happens in a file with lexical-binding being
`nil'?  Or the use of the function defined using it?

After all, apply-partially was first defined when lexical binding was
not available in Emacs.  So some uses might depend on particular
semantics in non-lexical-binding files?

I am just blindly guessing here.

-- 
David Kastrup



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: What's up with apply-partially?
  2015-01-24  8:54     ` David Kastrup
@ 2015-01-25 14:32       ` Stefan Monnier
  2015-01-25 19:45         ` [PATCH] Let apply-partially make use of lexical binding in subr.el David Kastrup
  0 siblings, 1 reply; 11+ messages in thread
From: Stefan Monnier @ 2015-01-25 14:32 UTC (permalink / raw)
  To: David Kastrup; +Cc: Leo Liu, emacs-devel

>>> I have been wondering this myself. I wonder if it was a workaround from
>>> the time when lexical-binding was not activated in subr.el?
>> Yes, I think this is the explanation.  Feel free to change it,
> Huh.  Perhaps this causes different behavior depending on whether the
> _use_ of apply-partially happens in a file with lexical-binding being
> `nil'?

No.

> Or the use of the function defined using it?

Neither.

> After all, apply-partially was first defined when lexical binding was
> not available in Emacs.

That's right, but it was defined differently then.  When lexical-binding
appeared, it made it possible to re-implement apply-partially
differently so as to avoid the problem of name-capture.  That's the code
in use now.  At that time, subr.el was not yet using lexical-binding, so
I did not just use a "normal closure".

> So some uses might depend on particular
> semantics in non-lexical-binding files?

No.


        Stefan



^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH] Let apply-partially make use of lexical binding in subr.el
  2015-01-25 14:32       ` Stefan Monnier
@ 2015-01-25 19:45         ` David Kastrup
  2015-01-27 16:12           ` David Kastrup
  0 siblings, 1 reply; 11+ messages in thread
From: David Kastrup @ 2015-01-25 19:45 UTC (permalink / raw)
  To: emacs-devel; +Cc: David Kastrup

* subr.el (apply-partially): Use lexical binding here.

See
<URL:http://lists.gnu.org/archive/html/emacs-devel/2015-01/msg00784.html>
for discussion.
---
 lisp/ChangeLog | 4 ++++
 lisp/subr.el   | 4 ++--
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 70293af..7cd831c 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,7 @@
+2015-01-25  David Kastrup  <dak@gnu.org>
+
+	* subr.el (apply-partially): Use lexical binding here.
+
 2015-01-25  Stefan Monnier  <monnier@iro.umontreal.ca>
 
 	* emacs-lisp/cl-generic.el (cl--generic-no-next-method-function): New fun.
diff --git a/lisp/subr.el b/lisp/subr.el
index 0534585..4dee603 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -136,8 +136,8 @@ ARGS is a list of the first N arguments to pass to FUN.
 The result is a new function which does the same as FUN, except that
 the first N arguments are fixed at the values with which this function
 was called."
-  `(closure (t) (&rest args)
-            (apply ',fun ,@(mapcar (lambda (arg) `',arg) args) args)))
+  (lambda (&rest args2)
+    (apply fun (append args args2))))
 
 (defmacro push (newelt place)
   "Add NEWELT to the list stored in the generalized variable PLACE.
-- 
2.1.0




^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH] Let apply-partially make use of lexical binding in subr.el
  2015-01-25 19:45         ` [PATCH] Let apply-partially make use of lexical binding in subr.el David Kastrup
@ 2015-01-27 16:12           ` David Kastrup
  2015-01-29 15:01             ` Stefan Monnier
  0 siblings, 1 reply; 11+ messages in thread
From: David Kastrup @ 2015-01-27 16:12 UTC (permalink / raw)
  To: emacs-devel

David Kastrup <dak@gnu.org> writes:

> * subr.el (apply-partially): Use lexical binding here.
>
> See
> <URL:http://lists.gnu.org/archive/html/emacs-devel/2015-01/msg00784.html>
> for discussion.
> ---
>  lisp/ChangeLog | 4 ++++
>  lisp/subr.el   | 4 ++--
>  2 files changed, 6 insertions(+), 2 deletions(-)

Anything wrong with this one?  No reply, and not applied either.

-- 
David Kastrup



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] Let apply-partially make use of lexical binding in subr.el
  2015-01-27 16:12           ` David Kastrup
@ 2015-01-29 15:01             ` Stefan Monnier
  2015-01-29 15:17               ` David Kastrup
  0 siblings, 1 reply; 11+ messages in thread
From: Stefan Monnier @ 2015-01-29 15:01 UTC (permalink / raw)
  To: David Kastrup; +Cc: emacs-devel

> Anything wrong with this one?

No, nothing wrong, go ahead,


        Stefan



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] Let apply-partially make use of lexical binding in subr.el
  2015-01-29 15:01             ` Stefan Monnier
@ 2015-01-29 15:17               ` David Kastrup
  2015-02-05 17:55                 ` David Kastrup
  0 siblings, 1 reply; 11+ messages in thread
From: David Kastrup @ 2015-01-29 15:17 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

Stefan Monnier <monnier@IRO.UMontreal.CA> writes:

>> Anything wrong with this one?
>
> No, nothing wrong, go ahead,

I am not an Emacs developer but merely provided this patch as a courtesy
after the end of discussion.

-- 
David Kastrup



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] Let apply-partially make use of lexical binding in subr.el
  2015-01-29 15:17               ` David Kastrup
@ 2015-02-05 17:55                 ` David Kastrup
  0 siblings, 0 replies; 11+ messages in thread
From: David Kastrup @ 2015-02-05 17:55 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

David Kastrup <dak@gnu.org> writes:

> Stefan Monnier <monnier@IRO.UMontreal.CA> writes:
>
>>> Anything wrong with this one?
>>
>> No, nothing wrong, go ahead,
>
> I am not an Emacs developer but merely provided this patch as a courtesy
> after the end of discussion.

Submitted to the bug tracker as
<URL:http://debbugs.gnu.org/cgi/bugreport.cgi?bug=19785> since it
appears dead in the water.

-- 
David Kastrup



^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2015-02-05 17:55 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-23 22:14 What's up with apply-partially? David Kastrup
2015-01-24  3:05 ` Leo Liu
2015-01-24  5:01   ` Stefan Monnier
2015-01-24  8:54     ` David Kastrup
2015-01-25 14:32       ` Stefan Monnier
2015-01-25 19:45         ` [PATCH] Let apply-partially make use of lexical binding in subr.el David Kastrup
2015-01-27 16:12           ` David Kastrup
2015-01-29 15:01             ` Stefan Monnier
2015-01-29 15:17               ` David Kastrup
2015-02-05 17:55                 ` David Kastrup
2015-01-24  3:53 ` What's up with apply-partially? Artur Malabarba

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).