Yet Another Switch-Case Syntax Proposal
Marko Rauhamaa
marko at pacujo.net
Fri Apr 4 05:46:48 EDT 2014
>>>> Instead of disabling fallthrough by default, why not disable it all
>>>> together?
>>>
>>> I was tempted but there are cases in which it's useful. An example
No, it is never useful, it never was. It came into being by accident, a
design bug turned into an advertised feature.
>>> switch day casein ("Monday", "Thursday", "Wednesday", "Tuesday",
>>> "Friday"):
>>> gotowork = True
>>> continue
>>> casein ("Monday", "Thursday", "Wednesday", "Tuesday", "Friday"):
>>> daytype = "ferial"
>>> casein ("Saturday", "Sunday")
>>> daytype = "festive"
That "casein" next to "switch" bugs me. Did I already propose:
switch: local_sabbath()
case (1, 2, 3) as sabbath:
...
case 6:
...
else:
...
The key is to look at precedents:
try:
...
except (E1, E2) as e:
...
except ...:
...
finally:
...
and:
lambda: expression
The "switch: day" format is a hybrid of the "try" and "lambda" syntaxes
and would be compatible with existing Python editors as well as general
Python sensibilities.
Marko
More information about the Python-list
mailing list