Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #69660

Re: Yet Another Switch-Case Syntax Proposal

From Marko Rauhamaa <marko@pacujo.net>
Newsgroups comp.lang.python
Subject Re: Yet Another Switch-Case Syntax Proposal
Date 2014-04-04 12:46 +0300
Organization A noiseless patient Spider
Message-ID <87ioqpqvef.fsf@elektro.pacujo.net> (permalink)
References <8084-1396540962-768613@sneakemail.com> <mailman.8852.1396550862.18130.python-list@python.org> <533e6e58$0$29993$c3e8da3$5496439d@news.astraweb.com>

Show all headers | View raw


>>>> 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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: Yet Another Switch-Case Syntax Proposal Ethan Furman <ethan@stoneleaf.us> - 2014-04-03 11:23 -0700
  Re: Yet Another Switch-Case Syntax Proposal Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-04-04 08:33 +0000
    Re: Yet Another Switch-Case Syntax Proposal Marko Rauhamaa <marko@pacujo.net> - 2014-04-04 12:46 +0300
      Re: Yet Another Switch-Case Syntax Proposal Ian Kelly <ian.g.kelly@gmail.com> - 2014-04-04 10:02 -0600
        Re: Yet Another Switch-Case Syntax Proposal Marko Rauhamaa <marko@pacujo.net> - 2014-04-04 19:44 +0300
          Re: Yet Another Switch-Case Syntax Proposal Ian Kelly <ian.g.kelly@gmail.com> - 2014-04-04 11:55 -0600

csiph-web