Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed2a.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'syntax': 0.04; 'subject:Python': 0.06; 'assignment': 0.07; 'test,': 0.07; 'if,': 0.09; 'objects,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject: [': 0.09; 'subject:language': 0.09; 'python': 0.11; 'wrote': 0.14; 'times,': 0.14; 'c++)': 0.16; 'for,': 0.16; 'garbage': 0.16; 'pointers,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'semantics': 0.16; 'language': 0.16; 'wrote:': 0.18; 'variable': 0.18; "python's": 0.19; '(in': 0.22; 'sort': 0.25; "i've": 0.25; 'references': 0.26; 'certain': 0.27; 'header:X-Complaints-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'tim': 0.29; 'chase': 0.31; 'languages': 0.32; 'fri,': 0.33; "can't": 0.35; 'something': 0.35; 'but': 0.35; 'c++': 0.36; 'done': 0.36; 'ends': 0.38; 'to:addr :python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'even': 0.60; 'new': 0.61; 'offer': 0.62; 'mar': 0.68; 'etc),': 0.84; 'subject:NOT': 0.84; 'thing,': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dave Angel Subject: Re: Python language hack for C-style programmers [DO NOT USE!] :-) Date: Thu, 27 Mar 2014 21:44:51 -0400 (EDT) Organization: news.gmane.org References: <20140327110856.14991bb0@bigbox.christie.dr> X-Gmane-NNTP-Posting-Host: dpc6744199008.direcpc.com X-Newsreader: PiaoHong Usenet NewsReaders 1.36 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: 30 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1395970797 news.xs4all.nl 2878 [2001:888:2000:d::a6]:47897 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:69234 Chris Angelico Wrote in message: > On Fri, Mar 28, 2014 at 3:08 AM, Tim Chase > wrote: >> Multiple times, I've seen someone want something like what C-style >> languages offer where assignment is done in a test, something like >> >> if (m = re.match(some_string)): >> do_something(m) > > If you want a language where you can do this sort of thing, but the > semantics are like Python's (first-class complex objects, garbage > collection, references instead of pointers, pass-by-object, etc), > check out Pike. Its syntax is very much C's, or C++'s or Java's if you > prefer, but it functions very much the way Python does. You can even - > and you can't do this in C or, to my knowledge, C++ - declare a > variable inside an if, which is valid only in the body of that if: > > if (array m = Regexp.split2(some_pattern, some_string)) > do_something(m); > I don't know for certain about if, but you can declare (in C++) a new variable in for, which is a superset of if. Scope ends when the for does. -- DaveA