[Python-ideas] Modern language design survey for "assign and compare" statements
Chris Angelico
rosuav at gmail.com
Sun May 20 13:46:02 EDT 2018
On Mon, May 21, 2018 at 1:19 AM, Juancarlo Añez <apalala at gmail.com> wrote:
> IMPORTANT NOTE:
>
> Enabling "as" in "if" and "while" doesn't have to be at the expense of some
> form of assignment expression. We've been having this discussion as if has
> to be either one or the other, and there's no reason we can't have both (as
> mentioned before, "reduce()" is live and well in the libraries, for people
> who need to use it).
>
> I in particular would not like it at all if something like ":=" was at the
> expense of "as", and I think that others on the side of expanding "if" and
> "while" may feel the same way.
Let's suppose that the := syntax already existed in Python - that you
could write this:
if child_pid := os.fork():
parent(child_pid)
else:
child()
What would be the benefit of adding the "as child_pid" syntax? The
full assignment expression syntax completely covers all the jobs that
you can do with a capturing if statement.
ChrisA
More information about the Python-ideas
mailing list