unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Thuna <thuna.cing@gmail.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: `eval'ing form in the current lexical environment
Date: Mon, 08 Jul 2024 18:03:01 -0400	[thread overview]
Message-ID: <jwvfrsj1re6.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87ttgz36og.fsf@gmail.com> (Thuna's message of "Mon, 08 Jul 2024 23:38:55 +0200")

> Aha, I wasn't aware that that situation was considered illegal.

It's pretty much incompatible with the notion of compilation:
Usually, when you compile code like

    (foo (bar))

under the assumption that `foo` is a function, the code you generate
evaluates (bar) before doing anything else.  So by the time it looks at
`foo` it's too late: if `foo` turns out to be a macro you'd have to
"undo" the evaluation of (bar).

IOW, you're forced to do something like what you suggested, i.e. replace
*every* function call with

    (if (is-a-macro 'FUN)
        (handle-the-corner-case 'FUN 'ARGS)
      (FUN . ARGS))

so the above ends up compiled as if you had written:

    (if (is-a-macro 'foo)
        (handle-the-corner-case 'foo '(bar))
      (foo (if (is-a-macro 'bar)
               (handle-the-corner-case 'bar nil)
             (bar))))

which kills all hopes of generating good-quality code.

You can admittedly do better by "watching" the definition of functions
and keeping dependencies, so when a function gets redefined as a macro
you can throw away all the compiled code which depends on it (and
recompile it later as needed).

Nevertheless, it's costly and not considered worth the trouble.

The reverse is accepted, OTOH: you can take a macro and later turn it
into a function.  Code compiled when it was defined as a macro will
simply keep using the old definition until it gets recompiled.


        Stefan




  reply	other threads:[~2024-07-08 22:03 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-07 18:55 `eval'ing form in the current lexical environment Thuna
2024-07-07 19:16 ` Stefan Monnier via Users list for the GNU Emacs text editor
2024-07-08  2:07   ` Thuna
2024-07-08  2:49     ` Stefan Monnier
2024-07-08 21:38       ` Thuna
2024-07-08 22:03         ` Stefan Monnier [this message]
2024-07-08 22:42           ` Thuna

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=jwvfrsj1re6.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=help-gnu-emacs@gnu.org \
    --cc=thuna.cing@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.
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).