4 ms·
Can anyone confirm this is actual pattern matching and not the frankly ridiculous procedural version that was originally proposed? That proposal, to deliberate
by mjburgess 6y ago
Can anyone confirm this is actual pattern matching and not the frankly ridiculous procedural version that was originally proposed?
That proposal, to deliberately hobble pattern matching by making it a statement, was an egregious ideological campaign with genuinely absurd consequences.
- dflock 6y agoIt's this: https://www.python.org/dev/peps/pep-0634/ https://www.python.org/dev/peps/pep-0634/ - not sure which version that is?
- nneonneo 6y agoNot sure what you mean, but the accepted PEP does appear to be a statement. What was the alternative?
- the_duke 6y agoIn many languages match is an expression, so you can do things like `x = match y { ... }`, which is a very common use case. 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`.
- klyrs 6y agoI presume that the alternative to a statement is an expression. For example, the ternary operator x = (a if c else b) is an expression, where the conditional equivalent if c: x = a else: x = b is a statement.
- galkk 6y agomatch is a statement, but the syntax is very readable. https://www.python.org/dev/peps/pep-0636/#adding-conditions-to-patterns https://www.python.org/dev/peps/pep-0636/#adding-conditions-...
- chriswarbo 6y ago> the syntax is very readable 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!
- adsharma 6y agoI've been trying to find the motivation for making it a statement. Do you have links to any prior discussion? I maintain a transpiler that converts python to 6 type safe languages. Keeping match semantics similar makes it easier to transpile.
- ivirshup 6y agoStrong agree that this is hobbled by being a statement. 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?