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

Greg Ewing greg.ewing at canterbury.ac.nz
Fri Jul 17 04:38:41 CEST 2009


Jan Kaliszewski wrote:

> while foo(x) and bar() where:
>     foo = SOMETHING
>     def bar():
>         SOMETHING ELSE
> do:
>     THE
>     LOOP
>     BODY

That's kind of clever, although it does require
modifying the while-loop syntax, and if you're
doing that, there's not a lot of gain over
introducing a dedicated loop-and-a-half syntax.

Also, once we're allowed 'where' clauses on
while statements, people are going to want them
on other kinds of statements as well:

   if a == b where:
     a = foo()
     b = blarg()
   then:
     ...

   class Ham(Spam) where:
     class Spam:
       ...
   is:
     ...

   def f(x = default) where:
     default = whatever
   as:
     ...

   try:
     ...
   except eels where:
     eels = something_bad()
   do:
     ...

Where do we stop?

> while foo(x) and bar():
>     where:
>         foo = SOMETHING
>         def bar():
>             SOMETHING ELSE
>     THE
>     LOOP
>     BODY

I think I liked the first version better. There's
something jarring about the unindent half way
through without any keyword to mark the boundary.
Also the bare 'where' relating to the previous line
suggests some weird grammatical gymnastics going
on.

-- 
Greg



More information about the Python-ideas mailing list