Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #104879
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Encapsulation in Python |
| Date | Tue, 15 Mar 2016 11:12:26 +1100 |
| Lines | 69 |
| Message-ID | <mailman.138.1458000749.12893.python-list@python.org> (permalink) |
| References | <56E17985.7060002@benmezger.nl> <mailman.139.1457623672.15725.python-list@python.org> <6984dafc-fffd-4d46-a173-421bb5c142d2@googlegroups.com> <mailman.25.1457711277.26429.python-list@python.org> <4ddc3696-3f71-4598-98a6-929267f51fb9@googlegroups.com> <mailman.42.1457801128.12893.python-list@python.org> <56e53cd3$0$1586$c3e8da3$5496439d@news.astraweb.com> <1376c684-2e7f-417a-9683-e47789f019fe@googlegroups.com> <CALwzidm0PPzMBNYFyxhAv0Y3-2dLRA0J8wbcD6Qj5tGYf37SAQ@mail.gmail.com> <mailman.132.1457990663.12893.python-list@python.org> <nc7chi$lbu$1@dont-email.me> <mailman.133.1457994074.12893.python-list@python.org> <nc7ef9$sgf$1@dont-email.me> <mailman.137.1457997645.12893.python-list@python.org> <nc7it9$ejq$1@dont-email.me> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| X-Trace | news.uni-berlin.de NwWa719BXOV0NRnHBhxVqwxsd5ursC6LKUmQrG4ao75w== |
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.009 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'python,': 0.02; 'string.': 0.04; 'subject:Python': 0.05; 'cc:addr:python-list': 0.09; '[1]:': 0.09; '[2]:': 0.09; '[3]:': 0.09; 'brackets': 0.09; 'literal': 0.09; 'obj': 0.09; 'python:': 0.09; 'semantics': 0.09; 'python': 0.10; 'def': 0.13; '2016': 0.16; 'colons': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'integers,': 0.16; 'quoted': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'stop):': 0.16; 'utterly': 0.16; 'wrote:': 0.16; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'either.': 0.22; 'am,': 0.23; 'header:In-Reply-To:1': 0.24; 'testing': 0.25; 'define': 0.27; 'switch': 0.27; 'message- id:@mail.gmail.com': 0.27; 'restrict': 0.27; 'start,': 0.27; 'values': 0.28; 'equality': 0.29; 'notation': 0.29; 'there.': 0.30; "i'm": 0.30; 'work.': 0.30; '15,': 0.30; 'checks': 0.30; 'skip:_ 10': 0.32; 'implement': 0.32; 'statement': 0.32; 'class': 0.33; "skip:' 20": 0.34; 'tue,': 0.34; 'that,': 0.34; 'received:google.com': 0.35; 'could': 0.35; 'clear': 0.35; 'something': 0.35; 'but': 0.36; 'should': 0.36; 'there': 0.36; 'lines': 0.36; 'received:209.85': 0.36; 'cases': 0.36; 'success.': 0.36; 'subject:: ': 0.37; 'expect': 0.37; 'received:209.85.213': 0.37; 'requirement': 0.37; 'difference': 0.38; 'received:209': 0.38; 'anything': 0.38; 'or,': 0.38; 'end': 0.39; 'where': 0.40; 'forget': 0.60; 'your': 0.60; 'skip:u 10': 0.61; 'entire': 0.61; 'different': 0.63; 'complete': 0.63; 'within': 0.64; 'between': 0.65; 'mar': 0.65; 'here': 0.66; 'lack': 0.76; 'introduce': 0.79; "'when'": 0.84; "(don't": 0.84; 'chrisa': 0.84; 'coupled': 0.84; "it'd": 0.84; 'of?': 0.84; 'presumably': 0.84; 'syntax:': 0.84; 'terrible': 0.84; 'unacceptable': 0.84; 'to:none': 0.91; 'subject:skip:E 10': 0.96 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc; bh=zaQLt8aJAC09PY4WgY9FbWXYURLNz1PXVtITRuCKwXE=; b=BklqYgtvwHftfWZgWOQ/MCARfpF4Q/ZGSsPmeq/LexWCXm7AkTiQpi3SQbw2x6YCg7 1kiaTkK2SkdnnMLTeQgPw2Ed3adbD5sCZbVA8YoWr/Dg08/tR/gD58LL+WXwpcErNZRr KNmW2DrswK3sHSQJeHl4GcUGkL2/yRlO+6sBY4eGFCpuW7l7cmWRXv8RMVZRGvEbMIln Y3Tsmkl7Z+6msrHc42qu32qT44cxEG8vO9o07oftYs6FyjLuQ35QVhXgpKzUgP9QObUR oyKgXNCYhtV4F+Vajpt3fIt1KJxX0704X9We0Zz/pi89HMF/dfN+XjkL2f5ahm5UP0OC uJpQ== |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:cc; bh=zaQLt8aJAC09PY4WgY9FbWXYURLNz1PXVtITRuCKwXE=; b=Zulns8vCf05PVlP2if5ZihtB5jbIcOOYKRKACGfFF5cJNQVu+KAOsdebx48Mhr1mib YxKhS7wrIwtI4Rv6M+75C0i6diKB3CUUDHbRxNiYhB2pRFg7S3iLfwBog+Sx+1GTiRkz r5tXFztWs24JgIJRBJPraTqIauByuQ/5Fx35VTuBmTH1SBZ/9GR8kFc8wASCawO+03kv 9sD1wVvZhg2kkwuNbGS/5DWJeW0u+MUiSq4v6tKN+6VYS1pDA42qL14nUb8Gz3d7Dz89 N9dmE0YaU/Cn0fEmYRpRAlaTajKKYp603ACZepxxx4grMxf+y4uV1BkzERenBK6moOLD Ly4Q== |
| X-Gm-Message-State | AD7BkJLADWdFrHF6pjhUpkcFwCngaCQELMPF44SpAxXOHBEWlF25+In/U68yjMTjpA8u6IVraZpMOb224ocCBw== |
| X-Received | by 10.50.137.35 with SMTP id qf3mr20984874igb.92.1458000746806; Mon, 14 Mar 2016 17:12:26 -0700 (PDT) |
| In-Reply-To | <nc7it9$ejq$1@dont-email.me> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.21 |
| 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> |
| Xref | csiph.com comp.lang.python:104879 |
Show key headers only | View raw
On Tue, Mar 15, 2016 at 10:56 AM, BartC <bc@freeuk.com> wrote:
> I disagree. And presumably so do others as there are so many different
> attempts to implement switch, with varying degrees of success. Here's how I
> do it outside Python:
>
> switch c
> when 'A'..'Z','a'..'z','_' then
> ++name
> when '0'..'9' then
> ++numeric
> when "()[]<>{}" then
> ++brackets
> else
> ++other
> end
>
> Anything so terrible about that that Python needs to keep well clear of or
> that you think its users should be deprived of?
Yes: the complete lack of colons at the ends of lines that introduce
suites. This is utterly unacceptable in Python!
Seriously though - the one thing that I'm very concerned about here is
your brackets one. In Python, there's no reason to restrict 'switch'
to integers, so I would expect its semantics to be based on either
equality comparisons or inequality comparisons (possibly with a
requirement that all values be hashable); you could have something
like "when in <string>" but a simple "when <string>" would look to me
like it's testing for that entire string. (Don't forget that, in
Python, there's no difference between 'single quoted strings' and
"double quoted strings", as there is in C-like languages.)
Although... come to think of it, you could actually define it the
other way around: the 'when' statement checks if the current switch
object is contained within any of its arguments. Coupled with a
range-like object with its own literal syntax, that would pretty much
give you what you're looking at there. However, you'd need to have an
awkward notation for the cases where you _are_ looking for equality:
switch c:
when 'A'..'Z', 'a'..'z', ['_']:
++name
Or, in a long tree:
switch c:
when [1]:
...
when [2]:
...
when [3]:
...
Which could work. It'd be well-defined, and not unreasonable. It
would, however, be entirely predicated on a "comparison range" object
with a literal syntax:
class Range:
def __init__(self, start, stop):
self.start = start
self.stop = stop
def __contains__(self, obj):
return self.start <= obj <= self.stop
def __repr__(self):
return "%r..%r" % (self.start, self.stop)
But that's not overly hard either.
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: Encapsulation in Python Ian Kelly <ian.g.kelly@gmail.com> - 2016-03-10 08:27 -0700
Re: Encapsulation in Python Rick Johnson <rantingrickjohnson@gmail.com> - 2016-03-10 16:45 -0800
Re: Encapsulation in Python Ian Kelly <ian.g.kelly@gmail.com> - 2016-03-11 08:47 -0700
Re: Encapsulation in Python Rick Johnson <rantingrickjohnson@gmail.com> - 2016-03-11 18:39 -0800
Re: Encapsulation in Python Ian Kelly <ian.g.kelly@gmail.com> - 2016-03-12 09:44 -0700
Re: Encapsulation in Python Rick Johnson <rantingrickjohnson@gmail.com> - 2016-03-12 19:11 -0800
Re: Encapsulation in Python Steven D'Aprano <steve@pearwood.info> - 2016-03-13 21:11 +1100
Re: Encapsulation in Python Rick Johnson <rantingrickjohnson@gmail.com> - 2016-03-14 10:32 -0700
Re: Encapsulation in Python Ian Kelly <ian.g.kelly@gmail.com> - 2016-03-14 15:09 -0600
Re: Encapsulation in Python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-14 21:23 +0000
Re: Encapsulation in Python BartC <bc@freeuk.com> - 2016-03-14 22:07 +0000
Re: Encapsulation in Python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-14 22:20 +0000
Re: Encapsulation in Python BartC <bc@freeuk.com> - 2016-03-14 22:40 +0000
Re: Encapsulation in Python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-14 23:19 +0000
Re: Encapsulation in Python BartC <bc@freeuk.com> - 2016-03-14 23:56 +0000
Re: Encapsulation in Python Chris Angelico <rosuav@gmail.com> - 2016-03-15 11:12 +1100
Re: Encapsulation in Python BartC <bc@freeuk.com> - 2016-03-15 00:54 +0000
Re: Encapsulation in Python Chris Angelico <rosuav@gmail.com> - 2016-03-15 11:58 +1100
Re: Encapsulation in Python BartC <bc@freeuk.com> - 2016-03-15 01:22 +0000
Re: Encapsulation in Python Chris Angelico <rosuav@gmail.com> - 2016-03-15 13:02 +1100
Re: Encapsulation in Python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-15 00:28 +0000
Re: Encapsulation in Python BartC <bc@freeuk.com> - 2016-03-15 01:10 +0000
Re: Encapsulation in Python Chris Angelico <rosuav@gmail.com> - 2016-03-15 12:23 +1100
Re: Encapsulation in Python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-15 04:41 +0000
Re: Encapsulation in Python rurpy@yahoo.com - 2016-03-14 17:17 -0700
Re: Encapsulation in Python Chris Angelico <rosuav@gmail.com> - 2016-03-15 11:25 +1100
Re: Encapsulation in Python Steven D'Aprano <steve@pearwood.info> - 2016-03-15 13:06 +1100
Re: Encapsulation in Python Chris Angelico <rosuav@gmail.com> - 2016-03-15 13:14 +1100
Re: Encapsulation in Python Steven D'Aprano <steve@pearwood.info> - 2016-03-15 13:40 +1100
Re: Encapsulation in Python Rick Johnson <rantingrickjohnson@gmail.com> - 2016-03-14 21:08 -0700
Re: Encapsulation in Python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-15 00:47 +0000
Re: Encapsulation in Python Steven D'Aprano <steve@pearwood.info> - 2016-03-15 13:46 +1100
Re: Encapsulation in Python Chris Angelico <rosuav@gmail.com> - 2016-03-15 11:56 +1100
Re: Encapsulation in Python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-15 04:36 +0000
Re: Encapsulation in Python Steven D'Aprano <steve@pearwood.info> - 2016-03-15 13:01 +1100
Re: Encapsulation in Python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-15 04:45 +0000
Re: Encapsulation in Python Christian Gollwitzer <auriocus@gmx.de> - 2016-03-15 22:02 +0100
Re: Encapsulation in Python BartC <bc@freeuk.com> - 2016-03-16 00:39 +0000
Re: Encapsulation in Python BartC <bc@freeuk.com> - 2016-03-16 22:58 +0000
Re: Encapsulation in Python sohcahtoa82@gmail.com - 2016-03-14 11:11 -0700
Re: Encapsulation in Python Rick Johnson <rantingrickjohnson@gmail.com> - 2016-03-14 23:09 -0700
Re: Encapsulation in Python Rick Johnson <rantingrickjohnson@gmail.com> - 2016-03-11 18:56 -0800
Re: Encapsulation in Python Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2016-03-12 13:52 +1300
Re: Encapsulation in Python Rick Johnson <rantingrickjohnson@gmail.com> - 2016-03-12 08:49 -0800
Re: Encapsulation in Python Chris Angelico <rosuav@gmail.com> - 2016-03-13 08:10 +1100
Re: Encapsulation in Python Rick Johnson <rantingrickjohnson@gmail.com> - 2016-03-12 19:36 -0800
Re: Encapsulation in Python Chris Angelico <rosuav@gmail.com> - 2016-03-13 15:05 +1100
Re: Encapsulation in Python Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2016-03-14 12:35 +1300
Re: Encapsulation in Python Rick Johnson <rantingrickjohnson@gmail.com> - 2016-03-14 15:55 -0700
csiph-web