2 ms·
Judging by the votes you got, your proposal is not well-liked. In general, breaking Python's syntax rules to introduce block expressions or what you want to ca
by toxik 5y ago
Judging by the votes you got, your proposal is not well-liked.
In general, breaking Python's syntax rules to introduce block expressions or what you want to call it seems like a steep price to pay for what amounts to syntactic sugar in the end.
However, your proposal actually misses the mark in the same way as the actual match/case does as well. What would be /really/ handy in Python is something like
{'some_key': bind_value_to_this_name} = a_mapping
because it is so common, especially if you're consuming a JSON API. You of course see the myriad problems with the above.
I think you should read the PEPs on match/case, these things have actually been considered. One idea was to introduce a keyword to say which variables are inputs and which are outputs, but that also violates the general grammar in a way that isn't very nice.
The accepted solution has warts, I agree, but at some point you just have to accept that you can't reach some perfect solution.
- uryga 5y ago> Judging by the votes you got, your proposal is not well-liked. i'm at peace with that :) [1] > In general, breaking Python's syntax rules to introduce block expressions or what you want to call it seems like a steep price to pay for what amounts to syntactic sugar in the end. that's your opinion, i disagree! i think Python would be a better, more pleasant to use language if they figured this out. a girl can dream, ok? > What would be /really/ handy in Python is something like {'some_key': bind_value_to_this_name} = a_mapping yes, extending the destructuring syntax would be nice, i agree! but the original question was "Please suggest a pattern matching expression syntax [...]", and the post you were responding to was specifically talking about `match`'s syntax. [2] > I think you should read the PEPs on match/case i read them when they came out. i'm assuming you're referring to this section from PEP 622: > "In most other languages pattern matching is represented by an expression, not statement. But making it an expression would be inconsistent with other syntactic choices in Python." https://www.python.org/dev/peps/pep-0622/#id77 https://www.python.org/dev/peps/pep-0622/#id77 i believe Python's statement-orientatation kinda sucks, so to me this is just "things aren't great, let's stay consistent with that". yeah, yeah, "use a different language if you don't like it" etc. --- [1] well, maybe not quite, after all i'm here arguing about it. [2] `match` uses patterns like the one you described in `case` arms, but is distinct from them. i don't see why dict-destructuring syntax couldn't be added in a separate PEP.
- uryga 5y agopedantic addendum: looks like i messed up my PEPs -- i linked to PEP622, which was superseded by PEP635 [1]. the gist of it hasn't changed though. --- [1] https://www.python.org/dev/peps/pep-0635/#the-match-statement https://www.python.org/dev/peps/pep-0635/#the-match-statemen..., Ctrl+F "Statement vs. Expression"