unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: "rms@gnu.org" <rms@gnu.org>,
	Michael Heerdegen <michael_heerdegen@web.de>
Cc: "mail@daniel-mendler.de" <mail@daniel-mendler.de>,
	"larsi@gnus.org" <larsi@gnus.org>,
	"47992@debbugs.gnu.org" <47992@debbugs.gnu.org>,
	"monnier@iro.umontreal.ca" <monnier@iro.umontreal.ca>,
	"jakanakaevangeli@chiru.no" <jakanakaevangeli@chiru.no>
Subject: bug#47992: [External] : bug#47992: 27; 28; Phase out use of `equal` in `add-hook`, `remove-hook`
Date: Tue, 6 Jul 2021 02:37:07 +0000	[thread overview]
Message-ID: <SA2PR10MB44743D274793ED9EEE263643F31B9@SA2PR10MB4474.namprd10.prod.outlook.com> (raw)
In-Reply-To: <E1m0aC3-0004uL-Gh@fencepost.gnu.org>

> People are proposing a lot of work on a little wrinkle that isn't worth
> much effort.  There are other changes we could make that would
> really help users do editing.

Agreed.

> Here's an easy way to help users avoid such collisions: to say
> they should include a name in each anonymous lambda that they put on a
> hook in their init files -- a name based on the user's name.
> 
> Adding a name to a lambda is easy.  Just write the symbol after the
> argument list (and doc string and interactive spec, if any), like
> this: (lambda () rms-init-3 (glum-mode 1))
> 
> The mame will distinguish it from any otherwise-identical function
> such as (lambda () j-r-gensym (glum-mode 1))
> because they will not be equal.
> 
> Thus, the only change needed is in documentation.

I don't think that solves the problem ("little
wrinkle") raised by the bug report.  (But I agree
that the only change needed is documentation - just
advise users not to use anonymous functions as hook
functions.)

IIUC, the problem is not to _distinguish_ the
lambda.  It's kinda the opposite.  It's to let you
just type a lambda expression and have
`add|remove-hook' recognize it as being the _same_
function you gave it before.

Currently the test used for a lambda is `equal',
meaning that to remove a lambda you've added with
`add-hook' you need to provide a lambda (a list)
that's `equal' to the one you added originally.
(For a named function the function symbol is
simply tested using `eq'.)

Those who proposed solving this looked for a way
to enable an `eq' test for a lambda.  Lars
proposed to have users "name" anonymous functions
they put on hooks, and (presumably) to update the
`add|remove-hook' code to test for such a name
(if present) using `eq'.  (If a given lambda is
unnamed then the wrinkle is still a wrinkle.)

If your suggested way of naming a lambda were
used then the same approach would presumably
apply: change the `add|remove-hook' code to test
for such a name (if present) using `eq'.  And it
has the same problem: no good if not used.
___

I mentioned that if someone really wanted to go
down such a road (not something I'd encourage),
then there's no need to add a "name" possibility
- just use the doc-string possibility for lambdas.
The test (when a doc string is present) could
then be to use `eq' plus function `documentation'.

(That's no different from the test needed for a
lambda with a name - whether named your way or
another way: need to test for the presence of a
name, and if present test it with `eq'.  The test
for a name is analogous to the test for a doc
string with function `documentation'.)

But I and some others also think the whole attempt
to provide more or less `eq' testing for lambdas
is maybe misguided, and that users who today don't
bother to use a named function will likely also
not bother to name the lambdas they use on hooks.
(That goes also for "naming" using a doc string.)

We should, however (IMO) advise users not to use
anonymous functions as hook functions, in general,
and let them know why.  As you said, "the only
change needed is in documentation."

  reply	other threads:[~2021-07-06  2:37 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-24 12:11 bug#47992: 27; 28; Phase out use of `equal` in `add-hook`, `remove-hook` Daniel Mendler
2021-04-24 20:12 ` bug#47992: [External] : " Drew Adams
2021-04-24 20:23   ` Daniel Mendler
2021-04-24 21:20     ` Drew Adams
2021-04-24 21:34       ` Daniel Mendler
2021-04-24 22:30   ` Stefan Monnier
2021-04-24 22:38     ` Daniel Mendler
2021-04-24 23:04       ` Stefan Monnier
2021-04-24 23:38         ` Daniel Mendler
2021-04-25  1:16         ` Drew Adams
2021-04-25  3:08           ` Stefan Monnier
2021-04-25  4:57             ` Drew Adams
2021-04-25 13:52               ` Stefan Monnier
2021-04-25  1:16       ` Drew Adams
2021-04-25  1:23     ` Drew Adams
2021-04-25  3:10       ` Stefan Monnier
2021-04-25  4:57         ` Drew Adams
2021-04-25 10:33           ` Daniel Mendler
2021-04-25 13:56           ` Stefan Monnier
2021-05-02  9:09 ` Lars Ingebrigtsen
2021-05-02 10:37   ` Daniel Mendler
2021-05-03  8:50     ` Lars Ingebrigtsen
2021-07-06 14:44     ` Olivier Certner
     [not found]   ` <877di6udfy.fsf@web.de>
2021-07-04  1:09     ` Lars Ingebrigtsen
2021-07-04  2:35       ` Michael Heerdegen
2021-07-04  2:56         ` Lars Ingebrigtsen
2021-07-04  4:28           ` Michael Heerdegen
2021-07-04 13:36             ` Lars Ingebrigtsen
2021-07-04 17:08               ` bug#47992: [External] : " Drew Adams
2021-07-04 22:45                 ` Michael Heerdegen
2021-07-05 12:39                 ` Lars Ingebrigtsen
2021-07-06  1:48             ` Richard Stallman
2021-07-06  2:37               ` Drew Adams [this message]
2021-07-06  3:21                 ` bug#47992: [External] : " Michael Heerdegen
2021-07-07 23:57                 ` Richard Stallman
2021-07-06  9:46               ` Arthur Miller
2021-07-07 23:57                 ` Richard Stallman
2021-07-08  2:11                   ` Arthur Miller
2021-07-04 23:15       ` Michael Heerdegen

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=SA2PR10MB44743D274793ED9EEE263643F31B9@SA2PR10MB4474.namprd10.prod.outlook.com \
    --to=drew.adams@oracle.com \
    --cc=47992@debbugs.gnu.org \
    --cc=jakanakaevangeli@chiru.no \
    --cc=larsi@gnus.org \
    --cc=mail@daniel-mendler.de \
    --cc=michael_heerdegen@web.de \
    --cc=monnier@iro.umontreal.ca \
    --cc=rms@gnu.org \
    /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).