[Python-ideas] Non-boolean return from contains (original) (raw)
Guido van Rossum guido at python.org
Mon Jul 26 16:28:30 CEST 2010
- Previous message: [Python-ideas] Non-boolean return from __contains__
- Next message: [Python-ideas] Non-boolean return from __contains__
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Sun, Jul 25, 2010 at 10:50 PM, Masklinn <masklinn at masklinn.net> wrote:
On 2010-07-26, at 05:07 , Guido van Rossum wrote:
A lot of code for containers or that uses containers implicitly expects simple invariants to hold: for x in container: assert x in container Yeah, a lot of code using comparisons also breaks when comparisons don't return bools. It's a specialized use, but I don't see it as anathema. OTOH the real solution would be something like LINQ in C# (http://msdn.microsoft.com/en-us/netframework/aa904594.aspx, http://en.wikipedia.org/wiki/LanguageIntegratedQuery). Most of LINQ itself (the LINQ library, as opposed to the query syntaxes which are solely syntactic sugar and statically compiled into LINQ method calls) can already be implemented in Python.
Well, the point of allowing more general contains overloading is exactly to improve upon the query syntax -- you may call it syntactic sugar (often a derogatory term), but you currently cannot translate an 'in' operator into a parse tree like you can for '<' or '+'. (The other odd ducks are 'and' and 'or', though in a pinch one can use '&' and '|' for those. I forget in which camp 'not' falls.
The things that might be missing are some LINQ-supporting features. Likely expression trees[0], maybe (but probably not) less limited and terser lambdas.
That's exactly the point I am driving at here. :-)
-- --Guido van Rossum (python.org/~guido)
- Previous message: [Python-ideas] Non-boolean return from __contains__
- Next message: [Python-ideas] Non-boolean return from __contains__
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]