unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Richard Stallman <rms@gnu.org>
To: "João Távora" <joaotavora@gmail.com>
Cc: luangruo@yahoo.com, michael_heerdegen@web.de,
	nuclearspace@gmail.com, monnier@iro.umontreal.ca,
	emacs-devel@gnu.org
Subject: Re: Some improvements for cl-flet
Date: Tue, 12 Oct 2021 18:42:56 -0400	[thread overview]
Message-ID: <E1maQU4-0001QQ-3N@fencepost.gnu.org> (raw)
In-Reply-To: <CALDnm51UW4qApTEVK=eZzpVaQbUg2v3KE2dXT7e9jQBr5C9DDg@mail.gmail.com> (message from João Távora on Mon, 11 Oct 2021 22:26:33 +0100)

[[[ To any NSA and FBI agents reading my email: please consider    ]]]
[[[ whether defending the US Constitution against all enemies,     ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]

  > I'm not going to answer for Po Lu, but I'll only mention something not yet
  > said about this form, which is that it is so important to the Common Lisp
  > language that it's not even a macro, it's one of the fundamental "special
  > forms" of the language (added sometime in 1988, it seems).

That was after my involvement in Common Lisp, so I never heard of it.
However, I think I see why it is a special form rather than a macro.

A macro expands one Lisp expression into another Lisp expression.
Without some way to make a "variable" stand for magic slots, there was
no way to write a macro that would create such variables.  (What would
that macro expand into?)  So they had to make it a built-in execution
feature.

This doesn't mean it is a good feature to have in a language.  It
messes up the language semantics.  In Emacs we have some variables
with magical effects on editing, but as far as Lisp semantics is
concerned they are only variables.

The definition of `cl-symbol-macro' calls `macroexpand'.  The reason
that method is _possible_ is because the magic "variable" is defined
only inside one expression.  But it is still kludgy.

Worse, it operates by putting advice on `macroexpand'.

Code inside Emacs should _never_ create advice!  Never, ever!  Putting
advice on a function makes that function mysterious.  It obfuscates
debugging that function, because it function does something other than
what its code says.

If we are going to have `cl-symbol-macro', it should be rewritten to
bind a hook which `macroexpand' explicitly runs.  The hook does the
same work as the advice, but the call to run the hook is visible in
the code -- not mysterious magic.

From node Advising Named Functions in the Emacs Lisp Reference Manual:

      @code{advice-add} can be useful for altering the behavior of existing calls
    to an existing function without having to redefine the whole function.
    However, it can be a source of bugs, since existing callers to the function may
    assume the old behavior, and work incorrectly when the behavior is changed by
    advice.  Advice can also cause confusion in debugging, if the person doing the
    debugging does not notice or remember that the function has been modified
    by advice.

      For these reasons, advice should be reserved for the cases where you
    cannot modify a function's behavior in any other way.  If it is
    possible to do the same thing via a hook, that is preferable
    (@pxref{Hooks}).  If you simply want to change what a particular key
    does, it may be better to write a new command, and remap the old
    command's key bindings to the new one (@pxref{Remapping Commands}).

      If you are writing code for release, for others to use, try to avoid
    including advice in it.  If the function you want to advise has no
    hook to do the job, please talk with the Emacs developers about adding
    a suitable hook.  Especially, Emacs's own source files should not put
    advice on functions in Emacs.  (There are currently a few exceptions
    to this convention, but we aim to correct them.)  It is generally
    cleaner to create a new hook in @code{foo}, and make @code{bar} use
    the hook, than to have @code{bar} put advice in @code{foo}.

It looks like this is not visible enough.  Perhaps we should put this in
the top node for advising, and make more links to it.

-- 
Dr Richard Stallman (https://stallman.org)
Chief GNUisance of the GNU Project (https://gnu.org)
Founder, Free Software Foundation (https://fsf.org)
Internet Hall-of-Famer (https://internethalloffame.org)





  reply	other threads:[~2021-10-12 22:42 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-11 12:51 Some improvements for cl-flet akater
2021-09-11 23:32 ` Michael Heerdegen
2021-09-12  3:35   ` akater
2021-09-12 15:38     ` Stefan Monnier
2021-09-13  0:14     ` Michael Heerdegen
2021-09-13  2:26       ` Stefan Monnier
2021-10-07  2:32       ` akater
2021-10-07 18:03         ` Stefan Monnier
2021-10-08 21:57           ` Richard Stallman
2021-10-09  5:23             ` akater
2021-10-09  6:01               ` Michael Heerdegen
2021-10-09 23:37                 ` Richard Stallman
2021-10-10 10:41                   ` Po Lu
2021-10-10 20:27                     ` João Távora
2021-10-10 21:57                       ` Stefan Monnier
2021-10-11  0:45                       ` [External] : " Drew Adams
2021-10-11 21:16                     ` Richard Stallman
2021-10-11 21:26                       ` João Távora
2021-10-12 22:42                         ` Richard Stallman [this message]
2021-10-12  0:05                       ` Po Lu
2021-10-12  0:29                       ` Robin Tarsiger
2021-10-12 22:43                         ` Richard Stallman
2021-10-09 23:33               ` Richard Stallman
2021-10-09 23:33               ` Richard Stallman
2021-10-14  4:00               ` Michael Heerdegen
2021-09-23 22:37 ` [PATCH] " akater
2021-09-23 22:41   ` akater
2021-09-24  7:11     ` João Távora
2021-09-24 15:20       ` [PATCH] Some improvements for cl-flet, and some more akater
2021-09-24 16:22         ` João Távora
2021-09-25  1:28         ` Lars Ingebrigtsen
2021-09-25  8:37           ` João Távora
2021-09-24 20:30     ` [PATCH] Some improvements for cl-flet akater
2021-09-26  6:54     ` Lars Ingebrigtsen
2021-09-26 12:04       ` akater
2021-09-26 12:36         ` Lars Ingebrigtsen
2021-10-03  3:51     ` Stefan Monnier
2021-10-07  5:02       ` akater
2021-10-07 18:23         ` Stefan Monnier
2021-11-03 12:59           ` akater
2021-11-09 20:37             ` Stefan Monnier
2021-10-09  5:33       ` akater

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=E1maQU4-0001QQ-3N@fencepost.gnu.org \
    --to=rms@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=joaotavora@gmail.com \
    --cc=luangruo@yahoo.com \
    --cc=michael_heerdegen@web.de \
    --cc=monnier@iro.umontreal.ca \
    --cc=nuclearspace@gmail.com \
    /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).