[Python-ideas] Anaphoric if

Guido van Rossum guido at python.org
Sun Apr 25 01:24:18 CEST 2010


On Sat, Apr 24, 2010 at 4:01 PM, Andrey Fedorov <anfedorov at gmail.com> wrote:
>
>
> On Sat, Apr 24, 2010 at 6:48 PM, Guido van Rossum <guido at python.org> wrote:
>>
>> On Sat, Apr 24, 2010 at 1:00 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:
>> > Raymond Hettinger wrote:
>> >> Yes, this has come up before.
>> >> FWIW, I'm +1 on the idea,
>> >> especially if it can be also applied to while-loops.
>> >> It looks very readable
>> >
>> > Agreed, of the sundry embedded assignment proposals that come up
>> > semi-regularly, adding "as" clauses to if and while statements is the
>> > most viable (although possibly still not a good idea).
>>
>> It is not a good idea. In particular it is a mistake to assume that
>> endowing if- and while-statements with special syntax is going to
>> solve anything -- the problem is more generally that *expressions*
>> can't have such effects (in Python) and there's nothing particularly
>> special about the top-level expression in an if-statement.
>
> What about endowing if/while statements with syntax to assign names to their
> entire predicates only?
> - Andrey

Well my point is that it doesn't solve enough problems to make an exception.

See the zen of Python: "Special cases aren't special enough to break
the rules." Plus the problem it solves is not very important anyway
(so the clever response of looking at the next line in the zen doesn't
apply :-).

-- 
--Guido van Rossum (python.org/~guido)



More information about the Python-ideas mailing list