Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: 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; 'static': 0.04; 'subject:Python': 0.06; 'character,': 0.09; 'iac': 0.09; 'subject:into': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'translation': 0.12; 'bit.': 0.16; 'client:': 0.16; 'constants.': 0.16; 'enum': 0.16; 'flags,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'meanwhile,': 0.16; 'subject:variable': 0.16; 'switch.': 0.16; 'switches': 0.16; 'size,': 0.16; 'wrote:': 0.18; 'bit': 0.19; '(the': 0.22; 'command': 0.22; 'feb': 0.22; 'code,': 0.22; 'cc:addr:python.org': 0.22; 'char': 0.24; 'integer': 0.24; 'cc:2**0': 0.24; "i've": 0.25; 'handling': 0.26; 'switch': 0.26; 'tables': 0.26; 'this:': 0.26; 'gets': 0.27; 'header:In-Reply-To:1': 0.27; 'character': 0.29; 'topic': 0.29; 'compared': 0.30; 'message- id:@mail.gmail.com': 0.30; 'code': 0.31; 'getting': 0.31; 'fighting': 0.31; "they'll": 0.31; 'quite': 0.32; 'fri,': 0.33; 'actual': 0.34; 'could': 0.34; 'no,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'c++': 0.36; 'subject:?': 0.36; 'example,': 0.37; 'awesome': 0.38; 'window': 0.38; 'pm,': 0.38; 'either': 0.39; 'skip:n 30': 0.60; 'subject:Can': 0.60; 'most': 0.60; "you're": 0.61; "you'll": 0.62; 'here': 0.66; 'frequently': 0.68; 'hour': 0.70; 'cultural': 0.74; '*really*': 0.84; '9:02': 0.84; 'negotiate': 0.84; 'tide': 0.84; 'proposal,': 0.91; 'states,': 0.91; 'to:none': 0.92 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 :content-type; bh=fFGaLr4MtZx6xRxKwd0UJ+K4DqFsu6YV9EZ8aAL4xPo=; b=EZk5n/91TIb5LuEFSDl345CI/1iQo6KXRQfxCwJ3guM8/YaLPewIpT+aUYUX+5wAjd Sy9Lhy4cU7dU+xnjrRdLUPtBZZjJB9Mq16I4PmWrxhn4KaXCqkmWXxrJpWwpkHPoODYm bLkHsqkfpPbfiawKLz8qjWqpBS0LkrAo5P6tbeVlry0fYB1rNg9y4FEHS7NVmaUcImCe Fz1RcRyMHChlaNDPTup4WFEjwIL25tQGTiKebvBajQKBvOTyzLlRqcpVTjOQfpPWgGAe P4VePxzl0yhhUftQV6eY091wB/xfYG2NNIZNlx7lSx1JJ0SSOPZbmYsSMgmq686Ed4CA Pk2g== MIME-Version: 1.0 X-Received: by 10.68.197.36 with SMTP id ir4mr2901384pbc.46.1393585683839; Fri, 28 Feb 2014 03:08:03 -0800 (PST) In-Reply-To: <87ha7jy2qs.fsf@elektro.pacujo.net> References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> Date: Fri, 28 Feb 2014 22:08:03 +1100 Subject: Re: Can global variable be passed into Python function? From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 56 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1393585687 news.xs4all.nl 2885 [2001:888:2000:d::a6]:49730 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:67214 On Fri, Feb 28, 2014 at 9:02 PM, Marko Rauhamaa wrote: > PS On the topic of enums, when are we getting support for a switch > statement? I don't see that they're particularly connected. In my C code, I've used enums frequently as quick constants, often never switching on them. Conversely, I often use switch in C code with either integer or character constants. (ASCII character, of course, as that's all you get.) Take this, for example, from my C++ MUD client: enum {IS=0x00,ECHO=0x01,SEND=0x01,SUPPRESSGA=0x03,TERMTYPE=0x18,NAWS=0x1F,SE=0xF0,GA=0xF9,SB,WILL,WONT,DO=0xFD,DONT,IAC=0xFF}; That one happens to be used in a switch at one point, but it's also used in other ways, like this: static char naws[]={IAC,SB,NAWS,0,0,0,0,IAC,SE}; (The actual window size gets patched in separately, in case you're curious... but I suspect most people here won't be aware that IAC SB NAWS means Interpret-As-Command, Subnegotiation Begin, Negotiate About Window Size, and that this is a TELNET command sequence.) With bit flags, they'll never be used in switch: enum //Bitflags in hackity { HACK_ATAT=1, //Perform @@ -> fill-in translation HACK_AUTOEDIT=2, //Respond to the autoedit markers [now active by default] }; ... if (hackity&HACK_ATAT) ... Sometimes, they're just states, and they're assigned and/or compared for equality: enum {ic, court, citizen, trivia, sports, chancount} lastlinetype; Some things check if (lastlinetype == ic), but nothing ever switches on it. Meanwhile, here's a switch block from Gypsum that will never use enumerations: switch (max(delay,base)) { case 0..59: ... handling for <1 minute ... case 60..3599: ... handling for <1 hour ... default: ... handling for >= 1 hour ... } No, the features are quite independent. Python currently has dispatch tables and if/elif chains, and a strong cultural aversion to switch. You could change that by coming up with some *really* awesome proposal, but you'll be fighting against the tide a bit. ChrisA