No macros in Python

Peter Hansen peter at engcorp.com
Sun Dec 15 23:51:14 EST 2002


Terry Hancock wrote:
> 
> On Sunday 15 December 2002 12:44 pm,  Courageous  wrote:
> > Mike Meyer wrote:
> > > Python doesn't have macros. On the other hand, looking at the world
> > > through OO glasses rather than S-expression glasses means you don't
> > > need macros as often. But the topic comes up at irregular intervals,
> > > so someone may eventually come up with a way of doing macros in Python
> > > that is right - at which point it'll be added.
> >
> > In what way would macros (as I understand them... from C for example)
> > improve Python, other than possibly a small improvement in performance?

Bad quoting: I believe I and not Courageous wrote the above.

> I'm sure Mike meant "lisp-like macros", not C macros.  Not being a lisper,
> though, I can't say why those would be so indispensible, either. 

I read his response, which confirms what you suggest, but I still have not
grasped the *value* of doing this.  I don't seem to encounter anything 
while writing Python code which makes me think grumblingly to myself "dang,
if I had a macro facility this would be a lot easier", so I'm still unsure
what the value would be.

Mike's examples all involve changing the language's syntax (that's what
I gather from what I understood, anyway) which is widely considered to
be a Bad Thing, but he attempts to justify it by comparison with 
redefining operators.  The problem is, redefining operators is also a
Bad Thing unless you keep the meaning identical to or *very* close to 
the original, so the justification falls apart, in my opinion.  

If the only good macro is one which doesn't change the language syntax, 
then you don't really need the macro, goes my logic...

-Peter



More information about the Python-list mailing list