On Sat, Apr 19, 2014 at 10:42 AM, Lucas Malor <7vsfeu4pxg@snkmail.com> wrote:
On 19 April 2014 08:52, Bruce Leban bruce-at-leapyear.org |python-ideas-at-python..org| <vajg1g2cqt@sneakemail.com> wrote:
Here's a simple class that provides case like syntax. How would modifying the language be better than this?

I don't like the additional unneeded Case indentation. That's why I'm proposing a syntax with switch on the same line with the first case.

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.

And merely saving indentation is not IMHO a sufficient reason to add a new feature to the language especially since you're not actually saving any. 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):
    elif case((2,3)):
        print('tuple(two, three)')
    elif case(2, 3):
        print('two or three')
    elif case > 3:
        print('more than three')

--- Bruce
Learn how hackers think: http://j.mp/gruyere-security