On 7/3/2020 8:28 AM, Rhodri James wrote:
On 03/07/2020 00:12, Nick Coghlan wrote:
On Fri., 3 Jul. 2020, 2:27 am MRAB, firstname.lastname@example.org wrote:
match shape: try Point(x, y): ... try Rectangle(x0, y0, x1, y1, painted=True): ...
I'm actually surprised at how much I like that. It certainly gets me out of the C mindset and makes it easier for me to recognise that Point(x,y) isn't an instantiation.
I really like the verb subclause. A match statement *tries* to match an object to sequence of pattern options, accepting the first structure match. In C, the cases are values (bit patterns) and the matching is by 'equals'. For the proposed matching, equality is the trivial pattern match, but generally, a more complicated action is required. I have the impression that at least some match action failures could be detected by a caught exception, as in "try: x,y = obj" to see if obj matches pattern 'x,y'. Since exceptions are ignored, try: clauses may bee followed by another try: clause to try another pattern.