Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #69781

Re: Yet Another Switch-Case Syntax Proposal

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <torriem+gmail@torriefamily.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.006
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'operator': 0.03; 'syntax': 0.04; 'clause': 0.09; 'false.': 0.09; 'parsing': 0.09; '(without': 0.16; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 0.16; 'oddity': 0.16; 'slight': 0.16; 'subject:Case': 0.16; 'syntax,': 0.16; 'unlikely': 0.16; 'language': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'normally': 0.19; '(in': 0.22; 'header:User-Agent:1': 0.23; 'adds': 0.24; 'equivalent': 0.26; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'statement': 0.30; 'assumes': 0.31; 'block,': 0.31; 'comparison': 0.31; 'but': 0.35; 'really': 0.36; 'edge': 0.36; 'false': 0.36; 'keyword': 0.36; 'done': 0.36; 'message-id:@gmail.com': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'previous': 0.38; 'explain': 0.39; 'does': 0.39; 'though,': 0.39; 'to:addr:python.org': 0.39; 'enough': 0.39; 'either': 0.39; 'received:org': 0.40; 'easy': 0.60; 'expression': 0.60; 'skip:n 10': 0.64; 'effectively': 0.66; 'day': 0.76; "'case'": 0.84; 'opens': 0.91; 'subject:Proposal': 0.91
X-Virus-Scanned amavisd-new at torriefamily.org
Date Sun, 06 Apr 2014 14:13:30 -0600
From Michael Torrie <torriem@gmail.com>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20131118 Thunderbird/17.0.11
MIME-Version 1.0
To python-list@python.org
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>
In-Reply-To <CAPTjJmqjDL8+pNGv6pBhkh6LGzBAGmYghNQXzf8X=k_q0L=h7A@mail.gmail.com>
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.8962.1396815239.18130.python-list@python.org> (permalink)
Lines 35
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1396815239 news.xs4all.nl 2934 [2001:888:2000:d::a6]:33988
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:69781

Show key headers only | View raw


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


Thread

Re: Yet Another Switch-Case Syntax Proposal Michael Torrie <torriem@gmail.com> - 2014-04-06 14:13 -0600

csiph-web