[Python-3000] A plea for anonymous functions

Fredrik Lundh fredrik at pythonware.com
Thu Nov 16 11:01:05 CET 2006


Ivan Krstić wrote:

>> I'm not convinced that they do -- you can emulate LINQ today with 
>> generators and iterator tools and good old for-in statements:
> 
> No, you can't.

my sentence didn't end at that colon, though.

> For people following from home: when you query a database with
> LINQ, C# can construct the actual SQL *query* by introspecting the AST;
> you can't do that without first-class code blocks

of course you can.  all you need is the AST for the *query*, not the 
rest of the code.

     for record in (<this part is important>):
         process record

     gen = (for record in (<this part is important>))

e.g. something like

     for record in (select table: <generator expression on table>):
         process record

where the table is able to either execute the generator expression on 
itself, or analyze the AST and do an optimized query.

> And because the language is aware of what you're querying, it can
> compile the same LINQ query to SQL, or XQuery, or something else
> entirely, as needed.

well, Python's a dynamic language, so that has to be done by the 
collection, on the fly.  but that's not a problem, really.

>> *) there are plenty of hacks to address parts of this; everything from
>> algebra on custom objects (used by various SQL construction kits, RE 
>> construction kits, etc), code that analyzes an expression by passing 
>> special AST-building objects through it (used in PIL's point method, for 
>> example), and code that requires you to pass in the expression as a text 
>> string (or a ready-made "compiler" module AST-tree).
> 
> Please distinguish hacks from language support

oh, my use of "decent mechanism" implied that the things I labelled as 
"hacks" in the footnote weren't decent enough.

if you read my post again, you'll find that I said pretty much the same 
thing as you're saying, minus the "we absolutely must have full support 
for anonymous blocks to be able to do this" part.

</F>



More information about the Python-3000 mailing list