Hello, Le 15/07/2020 à 13:37, Mohammad Foroughi via Python-Dev a écrit : > Hi, I had an idea regarding the pattern matching issue of comparing with > a previous constant variable instead of assigning to a new local > variable. I'm not sure if this has been brought up before but instead of > using a symbol with the case statement what if we used a keyword. > > [...] > > Other ideas for the keyword are "const" or "static" but these 2 are more > difficult to recognise since they aren't in other parts of python but > the "global" keyword is already implemented so it would be easy to > understand.
What about simply "is", which is already a keyword? AFAIK "is" has no meaning as a prefix operator as of now, so hopefully it would not make the grammar ambiguous (how can one check that for sure?). match color: case is RED: print("red") case is BLUE: print("blue") case other: print(f"unknown color {other}") or with Rhodri James' example: match value: case is x: print("value matches") case Point(is x, y): print("value matches x, y captured") case Line(Point(is x1, y1), Point(x2, is y2)): print("wouldn't call that pretty, but not ugly either") Cheers, Baptiste P.S.: granted, it could mislead some users into thinking that the comparison is done with "is" instead of "=="; but then, patterns are special in many ways, users will have to just learn them… _______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-le...@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/TZEJHFALXL4OUBDYNQ5D6PEALUYHG57I/ Code of Conduct: http://python.org/psf/codeofconduct/