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

Paul Moore p.f.moore at gmail.com
Fri Jul 17 15:23:29 CEST 2009


2009/7/17 Chris Perkins <chrisperkins99 at gmail.com>:
> On Thu, Jul 16, 2009 at 2:51 PM, Paul Moore<p.f.moore at gmail.com> wrote:
>> 2009/7/16 Chris Perkins <chrisperkins99 at gmail.com>:
>>>> You've also disallowed
>>>>
>>>> x[i] = 12 where:
>>>>    i = some_complicated_expression()
>>
>> And yet the user's intent is obviously to use the i defined inside the
>> where (that's how functional languages work, so it's hardly an
>> unrealistic intent).
>
> I don't follow this argument - in what way is that how functional
> languages work?

Sorry, I should have said "Haskell, and some other functional
languages I vaguely recall working similarly" :-)

In Haskell, the expressions given names in the where clause are used
throughout the expression to the left of the where. Of course
immutability and referential transparency makes that a lot less
controversial...

> 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.

> 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.

> "Namespaces are one honking great idea -- let's do more of those!"
>
> And everyone knows, you can't argue with the Zen. ;)

"If the implementation is hard to explain, it's a bad idea."
"Simple is better than complex."

But the Zen can have arguments with itself :-)

Paul.



More information about the Python-ideas mailing list