[Python-ideas] Modern language design survey for "assign and compare" statements
apalala at gmail.com
Fri May 18 21:39:13 EDT 2018
> It appears assignment expressions are no longer the favored solution for
> "assign and compare" use case. Not one of these five newer languages
> 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
> been rather more limited to the "if" and "while" statements only. Several
> folks here have expressed the same desire to confine AE there. Since
> design goals are similar—to be safe and maintainable I'd recommend a
> strategy, with the addition of the list comprehension case. Going back to
> C-style solution seems like the wrong direction.
> Since that would mean this special assignment functionality is not allowed
> 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
> 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,
> "is not None" on the end.
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".
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas