[Python-ideas] Where-statement (Proposal for function expressions)
Gerald Britton
gerald.britton at gmail.com
Fri Jul 17 15:25:15 CEST 2009
Sometimes I use helper functions to make things easier to read.
However, I don't like unnecessary function calls since they are
expensive in Python compared to other languages. Still I might do
this:
def foo(x):
def bar(y):
...
return ... #something depending on y
...
return bar(z)
If I had a "where" clause I could write:
def foo(x):
...
return y where:
#compute y
Using "where" would have the advantage of avoiding a function call,
though I suppose it wouldn't save (much) stack space since it needs a
new scope anyway. I see the "where" clause as a useful way to
abstract a section of code to keep the high level in view, then break
it down as you go.
More information about the Python-ideas
mailing list