[Python-ideas] Introducing where clauses

Andrey Popp 8mayday at gmail.com
Mon Jun 22 13:08:23 CEST 2009

```On Mon, Jun 22, 2009 at 3:01 PM, Ben Finney<ben+python at benfinney.id.au> wrote:
> Andrey Popp <8mayday at gmail.com> writes:
>
>> Reading discussion on python-ideas about  "Accessing the result of
>> comprehension's expression from the conditional", I've came to the
>> idea of where clauses, similar to Haskell's.
>>
>> This solves the problem of recalculating of value multiple times. For
>> example, in the following expression:
>>
>>     [(f(x), f(x)) for x in some_iterable if f(x) < 2]
>
> New syntax isn't necessary to solve the above stated problem. For
> example, the following existing syntax is also a solution::
>
>    [(y, y) for y in (f(x) for x in some_iterable) if y < 2]
>
> For the proposed new syntax to be accepted, it would need to be somehow
> significantly superior to the existing syntax. Can you demonstrate how
> it's superior?

Your statement:

[(y, y) for y in (f(x) for x in some_iterable) if y < 2]

means producing a list by iterating over the generator, which iterates
over the some_iterable, it is correct in algorithmic way, but not in
semantic.
I did not made statement about impossibility of making this kind of
things in python right now, without where-clauses. It is only
syntactic sugar, but very expressive, I think.

```

More information about the Python-ideas mailing list