[Python-Dev] A Hygienic Macro System in Python?

Samuele Pedroni pedroni@inf.ethz.ch
Mon, 18 Mar 2002 22:37:56 +0100


From: Jeremy Hylton <jeremy@zope.com>
> On Mon, 18 Mar 2002 16:10:40 -0500
>  Tom Emerson <tree@basistech.com> wrote:
> > I find using 'unless' makes some things more readable. To
> > learn the
> > internals of the compiler I've been adding an unless
> > statement to
> > Python, but one shouldn't need to do this in order to add
> > useful
> > constructions like this.
> 
> Funny you should pick this example!  I have been struggling
> with a collection of C code where the author used an
> UNLESS() macro.  I find it obscures the program logic
> significantly.  In part, I'm sure it's because I don't use
> it in any of my own C code, so it's an oddball control flow
> constructs to my eyes.  I'm not sure that I'd like to see
> Python programmers acquire to many ways to spell if :-).
> 

You're right, but even some Common Lispers
would find adding sligthly different flavors of control structures,
a contrived use of macros.

The point of macros is to add mini-languages
such that you're main language is embedded in
them. The macros of CL GUI systems 
are examples of that, or templating macros,
and some resource handling macros.

Anyway I have toyed myself with the idea
of adding macros to Python, but the conclusion
is that macros do not fit in Python's ecology,
or at least that you should design them
from scratch trying radical new ideas. Python is not a Lisp-like
language, it is probably more like Smalltalk,
that means that anonymous blocks would be
more natural (probably still not natural enough).

regards.