[Python-ideas] Modern language design survey for "assign and compare" statements
Carl Smith
carl.input at gmail.com
Mon May 21 09:21:58 EDT 2018
>
> for v in iter(get_something, INCOVENIENT_SENTINEL):
> do_something(v)
>
> There are many ways round my use case, all of them inelegant. That has to
> be one of the less comprehensible alternatives.
In for-loops (because they include an assignment already) we can improve
this with more indicatively named functions in practice.
-- Carl Smith
carl.input at gmail.com
On 21 May 2018 at 14:14, Rhodri James <rhodri at kynesim.co.uk> wrote:
> On 21/05/18 12:29, Daniel Moisset wrote:
>
>> On 21 May 2018 at 12:05, Rhodri James <rhodri at kynesim.co.uk> wrote:
>>
>>
>>> Thanks for the analysis, but I'm afraid I must disagree with your
>>> recommendation. It was the thought I first had when Chris came out with
>>> his first draft of the PEP several months ago, but it's not enough to
>>> cope
>>> with my usual use cases. What I normally want is the Python equivalent
>>> of:
>>>
>>> while ((v = get_something()) != INCONVENIENT_SENTINEL)
>>> do_something(v);
>>>
>>> The condition expression itself is not what I want to capture; I need a
>>> subexpression, which the "as" syntax won't give me.
>>>
>>>
>>> That use case should be covered by
>>
>> for v in iter(get_something, INCOVENIENT_SENTINEL):
>> do_something(v)
>>
>
> There are many ways round my use case, all of them inelegant. That has to
> be one of the less comprehensible alternatives.
>
>
> --
> Rhodri James *-* Kynesim Ltd
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180521/b7cd61a7/attachment.html>
More information about the Python-ideas
mailing list