[Python-Dev] defmacro (was: Anonymous blocks)
shane at hathawaymix.org
Mon Apr 25 21:13:06 CEST 2005
Paul Moore wrote:
> I think the key difference with macros is that they act at compile
> time, not at run time. There is no intention here to provide any form
> of compile-time processing, and that makes all the difference.
> What I feel is the key concept here is that of "injecting" code into a
> template form (try...finally, or try..except..else, or whatever) .
> This is "traditionally" handled by macros, and I see it as a *good*
> sign, that the discussion has centred around runtime mechanisms rather
> than compile-time ones.
>  Specifically, cases where functions aren't enough. If I try to
> characterise precisely what those cases are, all I can come up with is
> "when the code being injected needs to run in the current scope, not
> in the scope of a template function". Is that right?
That doesn't hold if the code being injected is a single Python
expression, since you can put an expression in a lambda and code the
template as a function. I would say you need a block template when the
code being injected consists of one or more statements that need to run
in the current scope.
More information about the Python-Dev