[Python-ideas] Where-statement (Proposal for function expressions)

Chris Perkins chrisperkins99 at gmail.com
Fri Jul 17 23:13:23 CEST 2009


On Fri, Jul 17, 2009 at 9:23 AM, Paul Moore<p.f.moore at gmail.com> wrote:
>
>> I don't really see the problem with it. If you told people that the
>> where block only applies to the right-hand-side of an assignment, and
>> that the left-hand-side is always evaluated outside the scope of the
>> where block, I doubt there would be much confusion.
>
> That somewhat assumes that a where block is only used for assignments
> (or more accurately, that there's a special exception for the left
> side of an assignment not being included). That's at best a wart.

The "special case for assignments" is what I was assuming.  In fact, I
liked this proposal partly because the semantics seemed so obvious
that you could guess them and be right - but looking through this
thread, I see that the semantics are obvious to different people in
different ways.

For example, I see that many people seem to expect:

i = 1
x[i] = 3 where:
    i = 2

to mean "x[2] = 3", which I would find utterly surprising.

>> Again, I don't think that's a big deal. One solution is to disallow
>> global statements (if we're already disallowing stuff like break and
>> return, why not). Another is just "don't do that".
>
> More warts. At some point, the weight of the various exceptions make
> the basic idea not worth it.

That does worry me, I'll admit - if the code that you can legally
write in a where block is only a subset of Python, then, well...
that's just ugly.

Nevertheless, I find several of the examples to have such a
readability advantage - similar to the way that list comprehensions
are immediately and wonderfully more readable than building a list in
a for loop - that I'm still in favor of the idea.


Chris Perkins



More information about the Python-ideas mailing list