[IronPython] Extension methods...

Thane thane at magna-capital.com
Tue Sep 20 19:26:10 CEST 2005

Yes, Michael, preferred syntax was the point of the examples.  Although this
may simply be a case of "I'm familiar with Python syntax and I'm not
familiar with LINQ", there is a greater similarity between the Python list
comprehension and SQL syntax.  This makes it easy to jump between the SQL
data domain and the Python code domain.  It is interesting that this is one
of the goals of LINQ: to seamlessly integrate these domains.

Admittedly, Anders is right when he says that in SQL "the scope of the
variable flow is backwards".  It is.  I like the fact that using
"from-where-select" allows statement completion (this is a BIG plus for
compilers), while the SQL equivalent of "select-from-where" does not permit


> -----Original Message-----
> From: Michael Latta [mailto:lattam at mac.com]
> Sent: Tuesday, September 20, 2005 12:47 PM
> To: 'Discussion of IronPython'; thane at magna-capital.com
> Subject: RE: [IronPython] Extension methods...
> Keith,
> 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.
> Michael
> -----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
> first.
> -----
> 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
> Thane
> 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
> databases
> using the same syntax as you would for other IEnumerable objects.
> _______________________________________________
> users-ironpython.com mailing list
> users-ironpython.com at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

More information about the Ironpython-users mailing list