[Python-ideas] Where-statement (Proposal for function expressions)
Jan Kaliszewski
zuo at chopin.edu.pl
Thu Jul 16 19:16:50 CEST 2009
16-07-2009, 13:49 Nick Coghlan <ncoghlan at gmail.com> wrote,
(in thread 'Immemorial desire for "do-while"-likeconstruction'):
> Steven D'Aprano wrote:
>> On Thu, 16 Jul 2009 08:50:06 am Jan Kaliszewski wrote:
>>> Hello,
>>>
>>> The issue has been coming back repeatedly:
>>
>> And not very long ago at that.
>
> So often that there's even a PEP* that documents the pros and cons of
> different ideas and points out that a viable syntactic challenger to the
> "while True with inner break" approach has yet to be found.
Maybe the where-statement could be a candidate? Consider an example:
while foo(x) and bar() where:
foo = SOMETHING
def bar():
SOMETHING ELSE
do:
THE
LOOP
BODY
or maybe better:
while foo(x) and bar():
where:
foo = SOMETHING
def bar():
SOMETHING ELSE
THE
LOOP
BODY
and Daniel's idea of one-def-shortcut also could apply:
while setup(x < y + 9 or bzzz):
where def setup(cond):
SETUP
ACTIONS
return cond
THE
LOOP
BODY
And what about for-loop?
for i in smartgen():
where def smartgen():
SOME ACTIONS
yield SOMETHING
THE
LOOP
BODY
Cheers,
--
Jan Kaliszewski <zuo at chopin.edu.pl>
More information about the Python-ideas
mailing list