Yet Another Switch-Case Syntax Proposal

Ian Kelly ian.g.kelly at gmail.com
Fri Apr 4 12:02:21 EDT 2014


On Apr 4, 2014 3:51 AM, "Marko Rauhamaa" <marko at pacujo.net> wrote:
>
> >>> 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:
>        ...

I don't get what this is intended to do. First, why is the expression in
the first line after the colon? That doesn't match any existing block
syntax (as you note it matches lambda, but that's an expression-level
syntax). What's wrong with the much more natural "switch local_sabbath():"?

Second, "as" clauses are used in other contexts for local assignment. What
is the purpose of doing that here? How does this solve the problem of
explicitly denoting case multiplicity?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20140404/6dc08a93/attachment.html>


More information about the Python-list mailing list