unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: "Pierre L. Nageoire" <devel@pollock-nageoire.net>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 56596@debbugs.gnu.org, Lars Ingebrigtsen <larsi@gnus.org>
Subject: bug#56596: 29.0.50; void-variable cl--nm
Date: Mon, 18 Jul 2022 05:36:11 +0200	[thread overview]
Message-ID: <871quj6qj8.fsf@pollock-nageoire.net> (raw)
In-Reply-To: <jwv4jzgd5rs.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Sat, 16 Jul 2022 19:19:41 -0400")

Hi Stefan,

Thanks for these detailed explanations; I think I will be able to
modify my codes to make them work with this new cl-generic
implementation.

Best regards 

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>>> I can reproduce this -- but only when using dynamic binding.  When using
>>> lexical binding, things work fine.
>
> Indeed, `cl-defmethod` (and `cl-defgeneric`) aren't guaranteed to work in
> dynbind code.  They often do, admittedly.
>
>>> I've added Stefan to the CCs; perhaps he has some comments.
>>
>>   I suspect that cl-generic implementation has recently changed and that
>>   it should not be used nowadays exactly like it has been. Any small
>>   explanations from Stefan would be greatly appreciated !
>
> The "next method" is not known when we compile `cl-defmethod` but it is
> known when we build the "effective method", which is expected to be done
> much less often than actual calls to that method.
>
> The old code for `cl-defmethod` turned
>
>     (cl-defmethod I ((d raw-daughter))
>       (format "the daughter of %s"
>               (cl-call-next-method)))
>
> into something like
>
>     (cl-..register (raw-daughter)
>       (lambda (cnm d)
>         (format "the daughter of %s"
>                 (apply cnm))))
>
> forcing the caller to build a `cnm` closure which captures the args list
> containing the value of the `d` argument.  Also it made it difficult to
> implement `next-method-p` since that requires digging into this `cnm`
> closure to see if it's one of those that would signal no-next-method.
>
> The new code instead is a bit like:
>
>     (cl-..register (raw-daughter)
>       (lambda (nm)
>         (lambda (&rest args)
>           (let ((cnm (lambda (&rest cnmargs) (apply nm (or cnmargs args)))))
>             (destructive-bind (d) args
>               (format "the daughter of %s"
>                       (apply cnm)))))))
>
> This basically moves some of the code from the caller to here, which
> doesn't seem to buy us very much but:
> - it makes it much easier to implement `next-method-p` because now we
>   have access to the actual "next method", rather than to a closure that
>   combines the next methods with the saved arg list, so it's much easier
>   to tell if the next method is the one that signals no-next-method.
> - we occasionally get to skip building the `cnm` closure because we can
>   use λ-lifting instead (basically the byte-compiler gets to see both
>   parts of the code together and can thus change it: with this new code
>   we could actually improve the code generated by the byte-compiler
>   even further).
>
> Problem is that the new code relies on the use of currying (see how
> `nm` and `args` are now passed in a curried fashion), which is only
> possible with lexical scoping.
>
>
>         Stefan





  reply	other threads:[~2022-07-18  3:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-16  8:46 bug#56596: 29.0.50; void-variable cl--nm Pierre L. Nageoire
2022-07-16 11:12 ` Lars Ingebrigtsen
2022-07-16 18:06   ` Pierre L. Nageoire
2022-07-16 23:19     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-07-18  3:36       ` Pierre L. Nageoire [this message]
2022-07-16 22:42 ` Stefan Kangas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871quj6qj8.fsf@pollock-nageoire.net \
    --to=devel@pollock-nageoire.net \
    --cc=56596@debbugs.gnu.org \
    --cc=larsi@gnus.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).