[Python-Dev] assignment expressions: an alternative proposal (original) (raw)
Steven D'Aprano steve at pearwood.info
Tue Apr 24 19:35:26 EDT 2018
- Previous message (by thread): [Python-Dev] assignment expressions: an alternative proposal
- Next message (by thread): [Python-Dev] assignment expressions: an alternative proposal
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Tue, Apr 24, 2018 at 10:29:11PM +0100, Anthony Flury via Python-Dev wrote:
If Python is going to do assignment expressions we shouldn't overload parens in my opinion - we should have a separate operator - doing this avoids needing to exclude rebinding, and makes such expressions considerably more useful.
Exactly!
Yury's suggestion to prohibit rebinding existing names is throwing away the baby with the bathwater. Using assignment-expression to over-write an existing variable is only a error when it is a mistake, done by accident.
To satisfy the compiler, we have to invent new and unique names for what is conceptually the same variable being reused. Instead of simplifying your code, it will make it more complex.
Despite his statement that there's only one assignment, there are actually two: assignment that allows rebinding, and assignment that sometimes doesn't. The semantic differences between Yury's = and = are actually greater than the differences between = and :=
-- Steve
- Previous message (by thread): [Python-Dev] assignment expressions: an alternative proposal
- Next message (by thread): [Python-Dev] assignment expressions: an alternative proposal
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]