[IronPython] LINQ in IronPython?

Michael Foord fuzzyman at voidspace.org.uk
Thu Nov 8 17:52:45 CET 2007


Hernan M Foffani wrote:
>> It would be great to have LINQ in IronPython - but I don't think it can
>> be done without extending the Python syntax. Understandably the Python
>> community will be concerned about this.
>>
>> Fortunately Python has a built-in way of enabling (or disabling)
>> language features - the __future__ imports.
>>
>> If you could agree with the Python developers to get a 'reserved' flag
>> for LINQ (one that CPython promises never to use) then develoeprs could
>> enable LINQ by starting files with:
>>
>> from __future__ import LINQ
>>     
>
> Some time ago I was wondering if it would be possible to have an
> object that takes a generator expression and translates its AST
> into LINQ expressions (actually, not LINQ extended syntax but
> the .NET 3.0 API )
>
> With this approach, of course, you won't be able to get LINQ's
> full power inside Python, but I think that staying within Python
> syntax is nice.
>   

I've been thinking about a similar approach - where list comprehensions 
(or generator expressions) could actually translate to API calls on the 
iterable (the data provider). Perhaps with a magic method like '__query__'.

Python (or IronPython) would have to then check for this magic method in 
every list comprehension - perhaps hitting performance. It would also 
have to *keep* the AST for the filter expression. I think this still 
amounts to an extension of Python though by adding new protocols - but 
it is a nice generalisation. Generating queries from ASTs sounds 
non-trivial, but Microsoft have done it for LINQ. I have a blog entry 
about this waiting in the wings.

Just providing a LINQ function that takes a generator expression is an 
interesting approach. IronPython would still have to do some magic to 
generate an expression tree from the filter expression.

Michael
http://www.manning.com/foord

> To be honest I haven't gave it much thought to this so I don't know
> if it's possible, or even worth it, at all.
>
> Regards,
> -Hernán.
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>   




More information about the Ironpython-users mailing list