all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@IRO.UMontreal.CA>
To: "Clément Pit-Claudel" <cpitclaudel@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: A combination of defmacro, functionp, and quoted lambdas yields different results on consecutive evaluations
Date: Mon, 26 Feb 2018 12:31:45 -0500	[thread overview]
Message-ID: <jwv1sh77jxs.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <c9389610-fc2d-db48-bfef-0f82da971801@gmail.com> ("Clément Pit-Claudel"'s message of "Mon, 26 Feb 2018 12:08:25 -0500")

> Is that actually a usable criterion?  Any macro can quote or unquote its
> argument, right?

Everything can happen, indeed.  But usually a macro which takes a code
argument and puts it within a quote is perceived as a problem: e.g. it
tends to very quickly annoy its users because they can't refer to
lexically-scoped arguments any more.  Admittedly, for
with-eval-after-load this is not very problematic because it's unusual
to have with-eval-after-load elsewhere than at top-level, so making code
like:

    (let ((x 1))
      (with-eval-after-load FOO
        (message "%S" x)))

work correctly is not nearly as important as it is for many other macros.

Code looks a lot like data, but for reasons of lexical scoping,
*variables* are quite different from symbols, yet we don't have any data
to represent *variables* (so we use symbols instead).

> For example, the problem that I described about with-eval-after-load
> also happens with eval-after-load, yet the argument to that is quoted.

[ I was wondering when someone would notice.  ]

Indeed, when I introduced `with-eval-after-load` and I also changed
`eval-after-load` by adding a compiler macro which turns

     (eval-after-load FOO 'BAR)
into
     (eval-after-load FOO `(,(lambda () BAR)))

so that BAR can be properly eagerly macro-expanded, so the
byte-compiler can look at BAR and emit warnings about it, and also so
that BAR will be interpreted using lexical-binding if the containing
file uses lexical-binding.

Here's the kind of thing I had in mind (can't think of any concrete
example for it, tho, the motivation came from such cases in defadvice
and interactive forms instead, which had the same problem is keeping
code quoted thus preventing compilation and eager macroexpansion):

    (eval-when-compile (require 'cl))
    (eval-after-load FOO '(flet ...))

There are a few other places where we "undo" a quote, as in

    (mapcar '(lambda ...) ...)

These were all done because it seemed to be beneficial more often than
it is harmful.  I must admit that I wasn't 100% sure that "unquoting"
its arg was "more often beneficial", tho the fact that I haven't heard
anyone even mention this until now seems to argue that even tho it's
maybe not "more often beneficial" at least not often harmful.


        Stefan



  reply	other threads:[~2018-02-26 17:31 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-17 16:04 A combination of defmacro, functionp, and quoted lambdas yields different results on consecutive evaluations Clément Pit-Claudel
2018-02-17 21:58 ` Stefan Monnier
2018-02-18 15:17   ` Clément Pit-Claudel
2018-02-18 18:02     ` Stefan Monnier
2018-02-25 18:09       ` Clément Pit-Claudel
2018-02-26  3:18         ` Stefan Monnier
2018-02-26  5:40           ` Clément Pit-Claudel
2018-02-26 13:11             ` Stefan Monnier
2018-02-26 15:20               ` Clément Pit-Claudel
2018-02-26 16:31                 ` Stefan Monnier
2018-02-26 16:38                   ` Stefan Monnier
2018-02-26 17:08                     ` Clément Pit-Claudel
2018-02-26 17:31                       ` Stefan Monnier [this message]
2018-02-28 14:32                         ` Clément Pit-Claudel
2018-02-28 16:02                           ` Stefan Monnier
2018-02-26 17:01                   ` Clément Pit-Claudel
2018-02-26 17:13                     ` Stefan Monnier
2018-02-26 17:32                       ` Clément Pit-Claudel
2018-02-26 17:40                         ` Clément Pit-Claudel
2018-03-01  0:50                       ` Radon Rosborough
2018-02-27 21:35                     ` Stefan Monnier
2018-02-28 12:44                       ` Michael Heerdegen
2018-02-28 13:31                         ` Stefan Monnier
2018-02-28 14:26                       ` Clément Pit-Claudel
2018-02-28 23:12                         ` Stefan Monnier
2018-02-26 13:13             ` Stefan Monnier
2018-02-26 15:20               ` Clément Pit-Claudel
2018-02-26 16:33                 ` Stefan Monnier
2018-02-26 16:37         ` Michael Heerdegen
2018-02-26 17:15           ` Clément Pit-Claudel
2018-02-26 17:38             ` Stefan Monnier

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

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

  git send-email \
    --in-reply-to=jwv1sh77jxs.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=cpitclaudel@gmail.com \
    --cc=emacs-devel@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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.