* Understanding macros and the compilation flow
@ 2010-06-03 15:03 LanX
2010-06-03 17:22 ` Helmut Eller
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: LanX @ 2010-06-03 15:03 UTC (permalink / raw)
To: help-gnu-emacs
Hi
I've put the following code into *scratch* and did M-x eval-buffer and
got a for me suprising result:
-------------------
(defmacro mac () '(insert " ; => before "))
(defun func () (mac))
(func) ; => before
(defmacro mac () '(insert " ; => after"))
(func) ; => after
-----------------
Seems like I didn't understand the compilation process, for my
understanding the redefinition of the macro "mac" after defining the
function "func" should not effect the expansion anymore...
Please, what am I missing here?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Understanding macros and the compilation flow
2010-06-03 15:03 Understanding macros and the compilation flow LanX
@ 2010-06-03 17:22 ` Helmut Eller
[not found] ` <87fx14rpyi.fsf@kuiper.lan.informatimago.com>
[not found] ` <jwvljaulvog.fsf-monnier+gnu.emacs.help@gnu.org>
2 siblings, 0 replies; 5+ messages in thread
From: Helmut Eller @ 2010-06-03 17:22 UTC (permalink / raw)
To: help-gnu-emacs
* LanX [2010-06-03 17:03+0200] writes:
> Hi
>
> I've put the following code into *scratch* and did M-x eval-buffer and
> got a for me suprising result:
>
> -------------------
> (defmacro mac () '(insert " ; => before "))
>
> (defun func () (mac))
>
> (func) ; => before
>
> (defmacro mac () '(insert " ; => after"))
>
> (func) ; => after
> -----------------
>
> Seems like I didn't understand the compilation process, for my
> understanding the redefinition of the macro "mac" after defining the
> function "func" should not effect the expansion anymore...
>
> Please, what am I missing here?
func is evaluated not compiled. The evaluator expands macros every time
when func is called.
Helmut
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Understanding macros and the compilation flow
[not found] ` <87fx14rpyi.fsf@kuiper.lan.informatimago.com>
@ 2010-06-03 17:45 ` LanX
0 siblings, 0 replies; 5+ messages in thread
From: LanX @ 2010-06-03 17:45 UTC (permalink / raw)
To: help-gnu-emacs
ahh thanks, sorry ... Perl doesn't know this destinction.
There each eval will compile the source to byte-code before execution.
Anyway Perl5 doesn't have macros...
Thanks again! :)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Understanding macros and the compilation flow
[not found] ` <jwvljaulvog.fsf-monnier+gnu.emacs.help@gnu.org>
@ 2010-06-04 15:34 ` LanX
2010-06-04 16:48 ` Andreas Politz
0 siblings, 1 reply; 5+ messages in thread
From: LanX @ 2010-06-04 15:34 UTC (permalink / raw)
To: help-gnu-emacs
Hi
> What you're missing is that the time (and number of times) the macro is
> expanded depends on various factors. The Elisp interpreter by default
> only expands macro during execution (and throws away the result).
> But don't rely on it, because the byte-compiler does it differently, and
> the evaluator could also be changed to do it differently.
Sorry thats somehow irritating for me and sorry if it's trivial for
you.
So there are differences between executing a
a) compilation,
b) interpretation and
c) evaluation?
(I hope at least not between b and c)
And does this mean that an .el file executes differently from the
corresponding .elc ???
(of course compiled with the same emacs version)
And which case has the "default behaviour" I should rely on?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Understanding macros and the compilation flow
2010-06-04 15:34 ` LanX
@ 2010-06-04 16:48 ` Andreas Politz
0 siblings, 0 replies; 5+ messages in thread
From: Andreas Politz @ 2010-06-04 16:48 UTC (permalink / raw)
To: help-gnu-emacs
LanX <lanx.perl@googlemail.com> writes:
> Hi
>
>> What you're missing is that the time (and number of times) the macro is
>> expanded depends on various factors. The Elisp interpreter by default
>> only expands macro during execution (and throws away the result).
>> But don't rely on it, because the byte-compiler does it differently, and
>> the evaluator could also be changed to do it differently.
>
> Sorry thats somehow irritating for me and sorry if it's trivial for
> you.
>
> So there are differences between executing a
> a) compilation,
> b) interpretation and
> c) evaluation?
>
> (I hope at least not between b and c)
>
> And does this mean that an .el file executes differently from the
> corresponding .elc ???
> (of course compiled with the same emacs version)
>
>
> And which case has the "default behaviour" I should rely on?
There are certain pitfalls when writing macros and if you fall in one of
them, compiled code could behave differently compared to evaled
code. You should read about it here
(info "(elisp) Problems with Macros")
.
-ap
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-06-04 16:48 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-03 15:03 Understanding macros and the compilation flow LanX
2010-06-03 17:22 ` Helmut Eller
[not found] ` <87fx14rpyi.fsf@kuiper.lan.informatimago.com>
2010-06-03 17:45 ` LanX
[not found] ` <jwvljaulvog.fsf-monnier+gnu.emacs.help@gnu.org>
2010-06-04 15:34 ` LanX
2010-06-04 16:48 ` Andreas Politz
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).