That proposal, to deliberately hobble pattern matching by making it a statement, was an egregious ideological campaign with genuinely absurd consequences.
That proposal, to deliberately hobble pattern matching by making it a statement, was an egregious ideological campaign with genuinely absurd consequences.
I don't write much Python these days, but it being a statement rather than an expression is disappointing
It forces you to use a separate "output" variable or `return`.
x = (a if c else b)
is an expression, where the conditional equivalent if c:
x = a
else:
x = b
is a statement.https://www.python.org/dev/peps/pep-0636/#adding-conditions-...
Yet it can't be used in a lambda, it can't be assigned to a variable, it can't be used as an argument, it can't be called as a function, it can't be put in a datastructure, it can't be raised, it can't be returned, it can't be yielded, and so on for all the things that can't be done to statements.
Heck, we can't even match on a match!
I maintain a transpiler that converts python to 6 type safe languages. Keeping match semantics similar makes it easier to transpile.
Pattern matching is great for dispatch and overloading, but because it's a statement there's no way for users to add overloads.
There will have to be some `matches(pattern, object)` function in CPython. Why not make this available to users? Why make patterns syntax, not objects?