Saturday, February 11, 2006

Brett Cannon: Clarifications on LINQ

Brett Cannon: Clarifications on LINQ: "Calvin Spealman set me straight on the true importance of LINQ."

Well, what an interesting start to an article in my news reader. Yes, I am Calvin Spealman. Brett goes on to talk about some details of this, mostly repeating and rephrasing what I set him straight on (his words, not mine), in reguards to LINQ.

Although we can not, at this time, get the AST for any expressions or blocks prior to compilation, I don't expect or see how or why we would reach this at Python 2.6, either. Firstly, I don't see how python would no to not-compile anything without some special "this is meant to be used just for its AST" syntax. Secondly, I doubt it would be any cheaper to generate the AST without compiling it into bytecode, after factoring in the time it might take to figure out if you need to do so or not. The most likely and efficient way will probably be the most obvious, in this case: pass a function object, built with def or lambda, but expressions by themselves (ie, not lambdas) will be pretty unusable. Anything else would require some kind of mechanism to know that a parameter expects AST, and that would break the python function model. So, barring anything along the lines of function decorators that say "parameter 3 gets the expression's AST" and hooks in the function call mechanism to catch this sort of thing, I don't see the direction of the Python 2.6 comment. Besides, anything along those lines seems like it would pose some serious security risks.

Am I misunderstanding the statement?

1 comment:

Niki said...

You can get pretty far by passing objects into a lambda that override all operators, attribute access and so on, to find out what the lambda "does" inside with it's parameters. This can be used to build (something like) an AST of the passed function. I don't think it works if the lambda contained any loops or recursion, though.
BTW: Can LINQ do that? I've only seen simple expressions in the examples. That should be possible using python, too.

I write here about programming, how to program better, things I think are neat and are related to programming. I might write other things at my personal website.

I am happily employed by the excellent Caktus Group, located in beautiful and friendly Carrboro, NC, where I work with Python, Django, and Javascript.

Blog Archive