[IronPython] Extension methods...

Michael Latta lattam at mac.com
Tue Sep 20 18:47:16 CEST 2005

Your summary of LINQ is correct in technical details.  I believe that the
comment was about preferred syntax.  The same could be done for Python, by
allowing the list comprehension syntax to be used to produce expression
trees not just executable blocks.  This was the main thing I liked about
LINQ.  The language features to support it were not custom to that usage,
but could be used in other contexts.  Defining what Python specific
compiler/language features would yield the same flexibility is what caught
my attention.  At the run-time level interop would be useful, but at the
syntax level something that is more "Pythonish" would be nice.


-----Original Message-----
From: users-ironpython.com-bounces at lists.ironpython.com
[mailto:users-ironpython.com-bounces at lists.ironpython.com] On Behalf Of
Keith J. Farmer
Sent: Tuesday, September 20, 2005 9:38 AM
To: thane at magna-capital.com; Discussion of IronPython
Subject: RE: [IronPython] Extension methods...

LINQ is *very* simple.  It's simply, as Anders puts it, a pattern for
describing queries.  It's made useful by way of extension methods and
the compiler deciding to convert a lambda expression not into a
delegate, but into an expression tree.
The query methods (Where, OrderBy, Select, etc) take trees, and build up
a description of the query which is then evaluated only when enumerated.
This allows DLINQ, for example, to analyze the tree and produce a SQL
command to send to a database, or XLINQ to produce an XQuery expression,
or LINQ to just take it as-is.  If you'd used a list comprehension,
you'd end up pulling all the information down from the database (were
this a database table); since this is an expression that can be
analyzed, you can manipulate it before it's actually invoked.  
You can conceivably take the expression and ship it whole to some
service, for the service to deal with.  Were this a CLR host (such as
Yukon), you'd have, effectively, created a remoted procedure.
Thus, it's *not* the same as a Python comprehension.  The syntax could
be similar, but the compiler would decide what to do based on whether
the method in question takes a Func<> or an Expression<>.
So I would say you were close, but not quite accurate.  Take a few
passes through the spec -- it's much more interesting than it seems at
Keith J. Farmer // kfarmer at thuban.org

-----Original Message-----
From: users-ironpython.com-bounces at lists.ironpython.com
[mailto:users-ironpython.com-bounces at lists.ironpython.com] On Behalf Of
Sent: Tuesday, 20 September 2005 08:23

Here's the Python equivalent:

>>> numbers = [5, 4, 1, 3, 9, 8, 6, 7, 2, 0]
>>> lownums = [n for n in numbers if n < 5]
>>> lownums
[4, 1, 3, 2, 0]

For most simple extractions of this sort, I prefer the Python list
comprehension.  IMO, the power of LINQ comes from integrating to
using the same syntax as you would for other IEnumerable objects.

users-ironpython.com mailing list
users-ironpython.com at lists.ironpython.com

More information about the Ironpython-users mailing list