[Python-ideas] Allowing breaks in generator expressions by overloading the while keyword

M.-A. Lemburg mal at egenix.com
Fri Feb 21 14:03:20 CET 2014


On 21.02.2014 13:25, Nick Coghlan wrote:
> On 21 February 2014 22:18, Nick Coghlan <ncoghlan at gmail.com> wrote:
>> That's not very readable to most Python programmers, but what if you
>> could write something like:
>>
>>     isprime = all(n % p for p in takewhile((: ? ** 2 < n), primes_seen))
>>
>> This is somewhat similar to the implicit lambda proposal in
>> http://legacy.python.org/dev/peps/pep-0312/, but with the following
>> two essential differences:
>>
>> 1. The parentheses would be required (as per generator expressions,
>> and as is being discussed for except expressions)
>> 2. By using a "?" token within the implicit lambda, you would create a
>> lambda that takes a single argument. If there is no such token, then
>> it would take no arguments.
> 
> Oh, and under such a proposal, the generator expression:
> 
>     (x for x in seq)
> 
> would be semantically equivalent to:
> 
>     (: yield x for x in ?)(seq)
> 
> Currently, there's no underlying construct you can decompose a
> generator expression into, because there's no notation for a lambda
> expression with an anonymous parameter.

Hmm, this reminds me too much of regular expression syntax :-)

I wonder why people are so keen on stuffing too much logic into
a single line. Must be a twitter/SMS side-effect.

Programs don't get faster that way, they don't get more readable,
you don't get to do more things that couldn't do otherwise
and requiring a master in computer science to be able to understand
what goes on in one of those magical lines doesn't feel right
to me either, given that we are promoting Python as first
programming language.

Of course, tossing around ideas like these is fun and I don't
want to spoil it. Eventually something useful will come out of
these discussions, I'm sure :-)

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Feb 21 2014)
>>> Python Projects, Consulting and Support ...   http://www.egenix.com/
>>> mxODBC.Zope/Plone.Database.Adapter ...       http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________
2014-02-12: Released mxODBC.Connect 2.0.4 ...     http://egenix.com/go53

::::: Try our mxODBC.Connect Python Database Interface for free ! ::::::

   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611
               http://www.egenix.com/company/contact/


More information about the Python-ideas mailing list