[Python-ideas] Yet Another Switch-Case Syntax Proposal
Lucas Malor
7vsfeu4pxg at snkmail.com
Tue Apr 22 17:01:38 CEST 2014
On 20 April 2014 04:17, Bruce Leban bruce-at-leapyear.org |
python-ideas-at-python.org| <vajg1g2cqt at sneakemail.com> wrote:
>
> I found that the ugliest part of your proposal since it hides the first
> case and at the same time makes it appear special when it isn't.
>
Myabe yes, but if you "translate" it in an if-elif, also the if seems to be
"special".
The indentation isn't required with my little Case class. The following
> works just as well but lacks the visible scoping that the with statement
> provides (of course the scope of the case variable leaks in either version,
> but I could modify my class to fail if invoked after __exit__ or __del__)..
>
> 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140422/2c35aa6c/attachment.html>
More information about the Python-ideas
mailing list