help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: `eval'ing form in the current lexical environment


From: Stefan Monnier
Subject: Re: `eval'ing form in the current lexical environment
Date: Sun, 07 Jul 2024 15:16:30 -0400
User-agent: Gnus/5.13 (Gnus v5.13)

> 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 via email to

[Prev in Thread] Current Thread [Next in Thread]