[Python-Dev] AST manipulation and source code generation

Chad Whitacre chad at zetaweb.com
Thu May 26 15:11:49 CEST 2005


Thanks Jeremy. Also wandered off-list w/ Ka-Ping; posting here for 
posterity.


chad

-----

chad: BTW, how does the concept of AST transformations relate to the 
concept of (Lisp) macros? Am I right to think that they are similar?

?!ng: Absolutely.  In terms of mechanism, they're basically the same;
the main difference is that in Lisp, the transformations are a part
of the core language definition.

?!ng: Well, i should refine that a bit to say that the Lisp macro system
is a little more specific.  Whereas AST transformations in Python
are open-ended (you could generate any result you want), the key
interesting property of Lisp macros is that they are constrained
to be "safe", in the sense that the bindings of variable names are
always preserved.

chad: Hmmm ... I don't follow python-dev closely but hasn't there been 
resistance to macros in Python? Are we saying macros may be a good idea 
after all?

?!ng: resistance -> Yes.
?!ng: good idea -> Not really.  AST transformations are useful for 
experimenting with the language, but i don't think there is much 
enthusiasm for making these transformations a normal part of the way 
most programs are written.



More information about the Python-Dev mailing list