[Python-3000] A plea for anonymous functions

Ivan Krstić krstic at solarsail.hcs.harvard.edu
Thu Nov 16 10:35:19 CET 2006


Fredrik Lundh 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. You can emulate a tiny subset of it, as you yourself
note. 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, unless you get ugly.
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.

> *) 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, and note what I said:
"... but they all make the same requirement as LINQ if they're to not
look like utter warts." So yes, these can be done (to a degree), but
they're all nasty solutions, and the fact we have a legitimate need for
them -- I brought up SQLObject before in this context -- tells me people
are already making Python behave non-obviously (which was Guido's fear),
just in exceedingly ugly and arbitrarily limited ways.

-- 
Ivan Krstić <krstic at solarsail.hcs.harvard.edu> | GPG: 0x147C722D


More information about the Python-3000 mailing list