Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #69781
| Date | 2014-04-06 14:13 -0600 |
|---|---|
| From | Michael Torrie <torriem@gmail.com> |
| Subject | Re: Yet Another Switch-Case Syntax Proposal |
| References | <8084-1396540962-768613@sneakemail.com> <CALwzidmw0QbUbNw5PvwmHh+4ghguUhpEnY8TbBZYYyjZkpLBsw@mail.gmail.com> <CABbU2U8fcwZYBuDA6JNOdWgwkNaTWiPvCnR1Be4wCvF0vecU1g@mail.gmail.com> <CAPTjJmqjDL8+pNGv6pBhkh6LGzBAGmYghNQXzf8X=k_q0L=h7A@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.8962.1396815239.18130.python-list@python.org> (permalink) |
On 04/06/2014 12:07 PM, Chris Angelico wrote:
> This has a slight oddity of parsing (in that an expression can
> normally have a comparison in it); if you really want to use the
> result of a comparison inside a case block, you'd have to parenthesize
> it. But it's easy enough to explain to a human.
This syntax is almost identical to the if/elif/else syntax, though, no?
>
> case day in briefing_days:
> lunch_time = datetime.time(11, 30)
> meeting_time = datetime.time(12, 30)
> case not in briefing_days + festive_days:
> lunch_time = datetime.time(12)
> meeting_time = datetime.time(14)
> case in festive_days:
> go_to_work = False
> day_type = "festive"
> else:
> go_to_work = True
> day_type = "ferial"
>
> A case statement that opens with a comparison operator takes the value
> from the previous case (without re-evaluating it); a case statement
> that lacks a comparison altogether assumes == and does the above. In
> either case (pardon the pun), the check will be done only if the
> preceding case was false. An 'else' clause is effectively equivalent
> to a 'case' that's always true.
>
> Adds only one keyword to the language ("switch" is gone), and adds an
> edge case to parsing that's unlikely to come up in non-contrived code.
>
> ChrisA
>
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Yet Another Switch-Case Syntax Proposal Michael Torrie <torriem@gmail.com> - 2014-04-06 14:13 -0600
csiph-web