On 2020-07-02 15:48, Jim J. Jewett wrote:
Guido van Rossum wrote:
On Wed, Jul 1, 2020 at 5:50 PM Nick Coghlan firstname.lastname@example.org wrote:
The key thing I'm hoping for in PEP 622 itself is that "Syntactic compatibility with a possible future enhancement to assignment statements" be considered as a constraint on the syntax for case patterns.
That would certainly rule out ideas like writing stores as $x or x? or <x> etc., since it would be syntactically incompatible with current assignment statements.
No; it would be unfortunate that it creates a second way to do things, but it wouldn't rule them out. The problem Nick pointed out is for syntax that is already meaningful, but means something different.
self.y = 15
already has a meaning, but that meaning is NOT "don't really assign to X, I am using it as a constant defined elsewhere."
?x = 14 ?self.y = 15
do not yet mean anything, and if they end up being a more explicit (but also more verbose) variant of
x = 14 self.y = 15
that is probably sub-optimal, but it isn't any worse than :=
The slight variation triggered by the "?" of ?var would be shorthand for "and if you can't make the entire assignment work, pretend I never even asked", so that
?x, 0 = (4,5)
would not lose or shadow a previous binding of x.
IMHO, the assignment statement should remain as it is, not sometimes assign and sometimes not.
There could be another form that does matching:
try ?x, 0 = (4,5)
?x, 0 ?= (4,5)
Perhaps it could also be used as an expression, having the value True if it matches and False if it doesn't.