On 6/23/2020 5:56 PM, Barry Warsaw wrote:

     match:
         expression
     case arm1:
         pass
     case arm2:
         pass
     else:
         pass

nicely mirrors try/except and if/elif/else constructs so it looks quite natural.

Agreed as to the look of the form.

Some observations:

1. 'else' is equivalent of 'elif True', so two alternative keywords are not strictly needed. The proposal uses 'case _' as the parallel catchall to 'elif True'. If '_' were not otherwise being used as a wildcard, I might suggest that 'case' by itself be used to always match.

2. 'expression' is *not* a general statement, let alone a suite of such, and it is not natural in non-interactive code that the object resulting from an expression be magically captured to be *implicitly* referenced in later code (the patterns).

Even though match may be thought of as a type of multiple elifs, this has no parallel in if/elif/else statements. However, in try/except statements, raised exceptions *are* magically captured, to be *explicitly* referenced in 'except' tuples. 'Try' and 'match' both consist of a setup, multiple test:action pairs, and a default action. So a similar indent structure can easily seem appropriate.

3. A bonus of 'match' by itself is that re-based syntax colorizers, as in IDLE, could pretend that the keyword is 'match:' and avoid colorizing re.match, etc. Or a colorizer could check that 'match' is followed by ':'. Always colorizing 'case' seems like less of an issue as I think it is less common as a name.

--
Terry Jan Reedy
_______________________________________________
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/YTNXXREZIKBQ3TVTPRLVRJVSGAMD2DNB/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to