[Python-ideas] Introducing where clauses

Gerald Britton gerald.britton at gmail.com
Tue Jun 23 15:12:56 CEST 2009

Personally I like the idea of the "where" clause.  It works well in
Haskell since it is tied closely to how functions are often defined in
mathematics. e.g.

   Area of a circle = pi*r**2 where pi is 3.14159.... and r is the
radius of the circle

In Haskell, it makes for concise function definitions.  IIRC defining
functions without the "where" clause in Haskell is a Hassle with a
capital "H".  However Python suffers from no such problem.  Though I
like the idea as a concept, I see it as syntactic sugar for Python
that is essentially a solution in search of a problem.

On Tue, Jun 23, 2009 at 3:11 AM, Georg Brandl<g.brandl at gmx.net> wrote:
> Carl Johnson schrieb:
>> Andrey Popp wrote:
>>> I am not about list comprehension only, there are other cases for
>>> where-clause, for example lambdas:
>>>    f = lambda x: (x, y) if x > 0 else (x, 0) where y = g(x)
>> Yuck. This reminds me of why I gave up on the Haskell tutorial I was
>> working through. The reading of this line keeps bouncing back and
>> forth. "OK, function f, passing in x, returning x, y… Wait? What's y?
>> Is that from an external scope? Anyway, here's an if-else clause, and
>> oh, there's the y! It's the same as g(x). OK, so where all did they
>> use y? Hmm, lets see, looks like just the one spot…"
> I know what you mean :)  I think "where" is best used where you all
> but know exactly what the where-bound name refers to, but have to spell
> it out for the stupid computer somewhere...
> Georg
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas

Gerald Britton

More information about the Python-ideas mailing list