[Python-ideas] Allowing breaks in generator expressions by overloading the while keyword
Nick Coghlan
ncoghlan at gmail.com
Fri Feb 21 13:25:39 CET 2014
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.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-ideas
mailing list