[Python-ideas] Yet Another Switch-Case Syntax Proposal

Lucas Malor 7vsfeu4pxg at snkmail.com
Tue Apr 22 17:27:20 CEST 2014


Sorry, I didn't read it carefully. Anyway, youe example can be written as:

for i in range(5):
    print(i, end=' => ')
    if i == 1:
        print('one')
    elif i == (2,3):

         print('tuple(two, three)')

    elif i in (2, 3):
        print('two or three')
    elif i > 3:
        print('more than three')

    else:

        print('unmatched')


and it's much simpler to read. I suggested the switch statement for a
simpler alternative to the if-elif chain.



On 22 April 2014 17:15, Chris Angelico rosuav-at-gmail.com |
python-ideas-at-python.org| <iv1yq22odt at sneakemail.com> wrote:

> On Wed, Apr 23, 2014 at 1:01 AM, Lucas Malor <7vsfeu4pxg at snkmail.com>
> wrote:
> >> for i in range(5):
> >>     print(i, end=' => ')
> >>     case = Case(i)
> >>     if case(1):
> >>         print('one')
> >>     elif case((2,3)):
> >>
> >>         print('tuple(two, three)')
> >>
> >>     elif case(2, 3):
> >>         print('two or three')
> >>     elif case > 3:
> >>         print('more than three')
> >>
> >>     else:
> >>
> >>         print('unmatched')
> >
> >
> > Ok, but you have to nest it inside a for loop. Your class is a good
> > solution, but a new syntax does not need nesting in a with or a for
> > statement.
> >
>
> I don't think he *has* to nest it. My reading of the above is that
> it's the For-Case Paradigm [1], normally considered an anti-pattern
> but viable for demonstrating what happens in each case.
>
> ChrisA
>
> [1] http://thedailywtf.com/Articles/The_FOR-CASE_paradigm.aspx
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140422/ac11559e/attachment.html>


More information about the Python-ideas mailing list