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

Greg Ewing greg.ewing at canterbury.ac.nz
Sat Jul 18 05:33:59 CEST 2009


Steven D'Aprano wrote:

> But the where clause introduces *look-ahead* to the process:
> 
> def parrot():
>     x = 1
>     result = x+y+z where:  # look-ahead
>         y = 2
>         z = 3
>     return result

I think this example is too rarified to give much idea of
how readable a where-statement might be. In real life
you wouldn't use arbitrary names like x, y, z. You'd
choose something to make the expression meaningful in
its own right, so you can get the gist of what's going
on just from reading the first line. Then you only
need to look inside the where block if you want to
know the fine details.

Also, I don't think that "look ahead" is necessarily
harmful unless the stuff ahead has side effects.

We seem to be happy with "look somewhere else" when
calling a function, whose definition could appear
textually before or after the point of call.

-- 
Greg



More information about the Python-ideas mailing list