Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #69781 > unrolled thread
| Started by | Michael Torrie <torriem@gmail.com> |
|---|---|
| First post | 2014-04-06 14:13 -0600 |
| Last post | 2014-04-06 14:13 -0600 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Yet Another Switch-Case Syntax Proposal Michael Torrie <torriem@gmail.com> - 2014-04-06 14:13 -0600
| From | Michael Torrie <torriem@gmail.com> |
|---|---|
| Date | 2014-04-06 14:13 -0600 |
| Subject | Re: Yet Another Switch-Case Syntax Proposal |
| Message-ID | <mailman.8962.1396815239.18130.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web