[Python-ideas] Modern language design survey for "assign and compare" statements

Juancarlo Añez apalala at gmail.com
Fri May 18 21:39:13 EDT 2018


Conclusions
> ------------
>
> It appears assignment expressions are no longer the favored solution for
> the
> "assign and compare" use case.  Not one of these five newer languages
> supports
> them fully, as the language generations from C to C# did.
>
> Of those that have recognized the use case to be large enough—the solution
> has
> been rather more limited to the "if" and "while" statements only.  Several
> folks here have expressed the same desire to confine AE there.  Since
> Python's
> design goals are similar—to be safe and maintainable I'd recommend a
> similar
> strategy, with the addition of the list comprehension case.  Going back to
> the
> C-style solution seems like the wrong direction.
>
> Since that would mean this special assignment functionality is not allowed
> to
> be used everywhere, it alleviates the pressure to make it fit into
> with/import/except statements.  Furthermore, that frees up the keyword "as"
> again, which is Pythonic, short, memorable and has a history of being used
> for
> various assignment purposes, not to mention a prominent feature of SQL.
>
> In short, extend the "if/elif", "while", and comprehension to:
>
>     if pattern.search(data) as match:
>>
>     while read_next_item() as value:
>>
> May be best to disallow multiple assignment/conditions for now, but up for
> discussion.  That leaves comprehensions, which could support a EXPR as NAME
> target also:
>
>     filtered_data = [f(x) as y, x/y for x in data]
>
> or perhaps reuse of the if…as statement to keep it simpler:
>
>     filtered_data = [y, x/y for x in data if f(x) as y]
>
> That variant might need an extra test if f(x) returns a falsey value,
> perhaps
> "is not None" on the end.
>
> Thoughts?
> -Mike
>

Thanks for the research!

Which is the niche, and how influential can it be, to have Python divert
from the well learned "assignments must be statements".

Cheers!

-- 
Juancarlo *Añez*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180518/03205c5d/attachment.html>


More information about the Python-ideas mailing list