3 ms·
Pretty much all languages that implement pattern matching treat case statements as l-values, not r-values. `match x: case y: ...` basically means "execute `y =
by breuleux 6y ago
Pretty much all languages that implement pattern matching treat case statements as l-values, not r-values. `match x: case y: ...` basically means "execute `y = x`, enter the body if it succeeds, try the next case if it fails". Python does allow more things as a case than it does in an assignment, but with the exception of `case enum.NOT_FOUND` (which IMO is a mistake and should not have been allowed), it could use the exact same syntax for `y = x` and `case y` if it wanted to, and it would be perfectly logical.
In the programming language I made a while back, my match statement was similar to Python's, and every case statement was also a valid l-value, so you could write `Point(x, y) | (x, y) = something` or `123 = x`, which would fail unless `x == 123`.