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

Chris Angelico rosuav at gmail.com
Tue Apr 22 17:15:51 CEST 2014


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


More information about the Python-ideas mailing list