"Structural pattern matching" for Python, part 2
"Structural pattern matching" for Python, part 2
Posted Sep 18, 2020 4:23 UTC (Fri) by udifuchs (guest, #141354)In reply to: "Structural pattern matching" for Python, part 2 by HelloWorld
Parent article: "Structural pattern matching" for Python, part 2
I know that a computer parser could easily understand this syntax. Still, as a human, I find it confusing. Most keywords in python are followed by an expression. The case keyword is followed by a pattern that has a syntax similar to an expression. This is confusing.
The PEP mentions that assignment targets in python also look like expressions, but this is true in a very narrow way. It is a syntax error to write 'int(x) = 3', while 'case int(x):' is valid.
More specifically, while reading the is_tuple() example in the PEP, it took me a while to realize that LParen() is initialized in the original code but not in the new code. If LParen.__init__() has some side effects, the two versions of the code that look very similar could be very different.
