all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
To: help-gnu-emacs@gnu.org
Subject: Re: `eval'ing form in the current lexical environment
Date: Sun, 07 Jul 2024 15:16:30 -0400	[thread overview]
Message-ID: <jwva5it6mwo.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: 87ikxh3uc0.fsf@gmail.com

> How would I `eval' a form as though it were where the `(eval ...)' form
> was?  That is, is there an argument to LEXICAL I can pass such that
>   (... (eval form LEXICAL) ...)
> becomes identical to
>   (... <value-of-form> ...)

No.  If you know the relevant set of variables, you can do

    (eval form `((VAR1 . ,VAL1) (VAR2 . ,VAL2) ...))

but why not just put `form` in there?
Why exactly do you need `eval` in the generated code?

>   (defmacro (lambda-list head &rest args)
>     `(defun ,lambda-list
>        ...
>        (if (macrop #',head)
>            (eval (<processor> '(,head ,@args)))
>          (,head ,@argsyms))))

I'm afraid I had trouble following your explanation (not fault of
yours: it's just difficult to describe in prose what a code does,
especially when it itself manipulates code).
Could you show an example that illustrates why you need `eval` in there?

My naive self would tell you to use

    (defmacro (lambda-list head &rest args)
      `(defun ,lambda-list
         ...
         (if (macrop #',head)
             ,(<processor> `(,head ,@args))
           (,head ,@argsyms))))

Or maybe your "procesor" needs to traverse the code, and what you really
need is to macro-expand it beforehand, something like:

    (defmacro (lambda-list head &rest args)
      (let* ((code (macroexpand-all (... `(,head ,@args) ...)
                                    macroexpand-all-environment))
             (processed (<processor> code)))
        `(defun ,lambda-list
           ... ,code ...)))


- Stefan




  reply	other threads:[~2024-07-07 19:16 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 [this message]
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
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

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

  git send-email \
    --in-reply-to=jwva5it6mwo.fsf-monnier+emacs@gnu.org \
    --to=help-gnu-emacs@gnu.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 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.