Ian Bicking: the old part of his blog

Introspecting expressions in py3k

There was a bit of discussion on the python-3000 list about getting access to AST, and the manipulations one could do at that point. Several people chimed in; I wrote up several packages I know of that could make use of this:

Underlying this vaguely-defined feature is the same featureset as LINQ, and it's something that people have been doing in Python for some time despite the fact that the language doesn't support it particularly well. It would be in my personal top 3 features that I'd like to see in py3k.

Guido's reply was:

I believe I've seen something like this described for an experimental version of Haskell; they had an operator that you used to prefix an expression and it returned the AST for that expression. One important feature was that they also had the opposite feature -- you could use another operator in the thus-quoted expression and it would evalulate that subtree and a normal expression, and substitute the result in the tree. They probably used it to implement a macro facility (though the example I remember was a type-safe printf facility).

I'm going to place the ball firmly in the court of those who want this feature: please write a proposal and an implementation. All that work is not going to get your proposal accepted for certain, but it'll let me look at it.

(You know, I really hate to be in the position of the parent always saying "no". But there's gotta be someone who ensures that Python 3000 will in fact be Python 3000 and not Perl 7. There are many, many more possible changes to the language than can possibly be accepted. We have to prioritize.)

So, the challenge is out. In order to put this feature up for consideration:

So: if you are interested in this sort of feature, please pop on over to the python-3000 list so we can discuss it (that list seems like the best place to discuss, unless someone suggests otherwise).

Created 11 Apr '06

Comments:

Couple of years ago I was trying to understand Tomcat, and got stuck with its security model. To the best of my grasp of the core code, Tomcat was using an XML parser and introspection against the JVM to treat a configuration file like a script. Byzantine.

# Chris Smith

David Binger's talk was likely on Spec, a module which can be found in the QP web framework and in the Dulcinea package (a bolt on library of objects and UI suitable for QP or Quixote programmers).

Spec is useful enough all on its own. Its a single file, easy to comprehend, and once you start designing objects with it, you don't want to go back.

Its useful to look at some code that uses Spec - perhaps one of the Dulcinea objects like User or Item.

# Mike Watkins