[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: macroexpand and bytecomp.el
From: |
Stefan Monnier |
Subject: |
Re: macroexpand and bytecomp.el |
Date: |
Mon, 12 Feb 2024 16:24:07 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
> (defmacro byte-extrude-byte-code-vectors ()
> (prog1 (list 'setq 'byte-code-vector
> (get 'byte-code-vector 'tmp-compile-time-value)
> 'byte-stack+-info
> (get 'byte-stack+-info 'tmp-compile-time-value))
> (put 'byte-code-vector 'tmp-compile-time-value nil)
> (put 'byte-stack+-info 'tmp-compile-time-value nil)))
[...]
> (defvar tmp-var [1 2 3])
> (defvar my-var nil)
> (defmacro my-extrude ()
> (prog1 (list 'setq 'my-var 'tmp-var)
> (setq tmp-var nil)))
> (my-extrude)
I don't fully understand your question, but notice that in your macro
you use 'tmp-var in the `setq`, i.e. your macro returns code that uses
the name of the variable and not its content (so the variable will be
read *after* when the code is run rather than when it's macro-expanded),
whereas in `byte-extrude-byte-code-vectors` the macro executes
(get 'byte-code-vector 'tmp-compile-time-value) during the macro
expansion and thus returns code which contains the value therein.
IOW, `byte-extrude-byte-code-vectors` is more akin to:
(defmacro my-extrude ()
(prog1 (list 'setq 'my-var tmp-var)
(setq tmp-var nil)))
- Stefan