
On Mon, Jun 22, 2009 at 3:01 PM, Ben Finney<ben+python@benfinney.id.au> wrote:
Andrey Popp <8mayday@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.