* macro that uses local variables
@ 2023-08-08 0:32 Heime
2023-08-08 1:27 ` Emanuel Berg
0 siblings, 1 reply; 4+ messages in thread
From: Heime @ 2023-08-08 0:32 UTC (permalink / raw)
To: Heime via Users list for the GNU Emacs text editor
I am using the rocket equation in this macro. I want to change it such that
the arguments are set as local variables. How does one code that ?
(defmacro booster-velocity-change
(specific-impulse standard-gravity initial-mass final-mass)
"Compute change of velocity using rocket equation."
`(* (* ,specific-impulse ,standard-gravity)
(log (mass-ratio ,initial-mass ,final-mass))) )
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: macro that uses local variables
2023-08-08 0:32 macro that uses local variables Heime
@ 2023-08-08 1:27 ` Emanuel Berg
2023-08-09 3:09 ` Heime
0 siblings, 1 reply; 4+ messages in thread
From: Emanuel Berg @ 2023-08-08 1:27 UTC (permalink / raw)
To: help-gnu-emacs
Heime wrote:
> I am using the rocket equation in this macro [...]
>
> (defmacro booster-velocity-change
> (specific-impulse standard-gravity initial-mass final-mass)
> "Compute change of velocity using rocket equation."
> `(* (* ,specific-impulse ,standard-gravity)
> (log (mass-ratio ,initial-mass ,final-mass))) )
There is no reason to write a macro for this
simple computation.
> I want to change it such that the arguments are set as local
> variables
Lexical scope, defun, arguments, if need be `let'. It is
super easy.
If you start thinking "how do I solve my problem?" instead of
"how do I do <something> in Emacs", everything will be much
easier for you ...
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: macro that uses local variables
2023-08-08 1:27 ` Emanuel Berg
@ 2023-08-09 3:09 ` Heime
2023-08-09 21:02 ` Emanuel Berg
0 siblings, 1 reply; 4+ messages in thread
From: Heime @ 2023-08-09 3:09 UTC (permalink / raw)
To: Emanuel Berg; +Cc: help-gnu-emacs
Sent with Proton Mail secure email.
------- Original Message -------
On Tuesday, August 8th, 2023 at 1:27 PM, Emanuel Berg <incal@dataswamp.org> wrote:
> Heime wrote:
>
> > I am using the rocket equation in this macro [...]
> >
> > (defmacro booster-velocity-change
> > (specific-impulse standard-gravity initial-mass final-mass)
> > "Compute change of velocity using rocket equation."
> > `(* (* ,specific-impulse ,standard-gravity)
> > (log (mass-ratio ,initial-mass ,final-mass))) )
>
>
> There is no reason to write a macro for this
> simple computation.
>
> > I want to change it such that the arguments are set as local
> > variables
>
>
> Lexical scope, defun, arguments, if need be `let'. It is
> super easy.
>
> If you start thinking "how do I solve my problem?" instead of
> "how do I do <something> in Emacs", everything will be much
> easier for you ...
In the context of a macro, the 'let' command should happen outside tho macro
quote. With the quote expression in the body. Am I right ?
(defmacro booster-velocity-change
(specific-impulse initial-mass final-mass)
"Compute change of velocity using rocket equation."
(let ( (gravity 9.81) )
`(* (* ,specific-impulse ,gravity)
(log (mass-ratio ,initial-mass ,final-mass))) ))
> --
> underground experts united
> https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: macro that uses local variables
2023-08-09 3:09 ` Heime
@ 2023-08-09 21:02 ` Emanuel Berg
0 siblings, 0 replies; 4+ messages in thread
From: Emanuel Berg @ 2023-08-09 21:02 UTC (permalink / raw)
To: help-gnu-emacs
Heime wrote:
> In the context of a macro, the 'let' command should happen
> outside tho macro quote. With the quote expression in the
> body. Am I right ?
Why do you want to use a macro to begin with?
> (defmacro booster-velocity-change
> (specific-impulse initial-mass final-mass)
> "Compute change of velocity using rocket equation."
>
> (let ( (gravity 9.81) )
> `(* (* ,specific-impulse ,gravity)
> (log (mass-ratio ,initial-mass ,final-mass))) ))
Gets easier with a `defun', and then you can remove all the
complicated quoting as well ...
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-08-09 21:02 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-08 0:32 macro that uses local variables Heime
2023-08-08 1:27 ` Emanuel Berg
2023-08-09 3:09 ` Heime
2023-08-09 21:02 ` Emanuel Berg
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).