Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin1!goblin.stu.neva.ru!uio.no!news.tele.dk!news.tele.dk!small.news.tele.dk!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'syntax': 0.04; 'subject:Python': 0.06; 'assignment': 0.07; 'test,': 0.07; 'false,': 0.09; 'if,': 0.09; 'objects,': 0.09; 'subject: [': 0.09; 'subject:language': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'times,': 0.14; 'boolean': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'garbage': 0.16; 'pointers,': 0.16; 'semantics': 0.16; 'language': 0.16; 'wrote:': 0.18; 'variable': 0.18; "python's": 0.19; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'sort': 0.25; "i've": 0.25; 'references': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'tim': 0.29; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'chase': 0.31; 'languages': 0.32; 'fri,': 0.33; "can't": 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'c++': 0.36; 'done': 0.36; 'sure': 0.39; 'even': 0.60; 'offer': 0.62; 'more': 0.64; 'mar': 0.68; 'etc),': 0.84; 'subject:NOT': 0.84; 'thing,': 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=yqzW93NFow0ku8fFg2DFPwstCAmxOFsAa8WRttJhS1A=; b=fxJLrFyYEsdUMDYj+xgtyAju4xneOmii8qTteQlQMySBuQ4NFs+n5pyC07pGAs2nrg /NJvgG6rONVZaKgnnFdduErImUOTxdfpKhF45A2sozHx16mwXr8xFFXlZuzGnOd+mG+z oMsqdc0uxO1dNRgpRA7Am730xvu0AGHqnGi8ml23EMI5KiPV6C70G7qn1/xCC5r3kgbT cRTzUMxh+0NQwiswnnK8ZuwRFN1J0YsoGj1NrxFa9MOBLyS/UCOdqs6aC8VtK+GZrbP5 SYPmSwdEl/y8mLd4nb1AsojCms+X+tCvUNPPA8N/ws2rRSmfPqDqpVbitFLfsK2dbArq Up0g== MIME-Version: 1.0 X-Received: by 10.66.27.202 with SMTP id v10mr2713499pag.127.1395937180738; Thu, 27 Mar 2014 09:19:40 -0700 (PDT) In-Reply-To: <20140327110856.14991bb0@bigbox.christie.dr> References: <20140327110856.14991bb0@bigbox.christie.dr> Date: Fri, 28 Mar 2014 03:19:40 +1100 Subject: Re: Python language hack for C-style programmers [DO NOT USE!] :-) 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: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1395937189 news.xs4all.nl 2934 [2001:888:2000:d::a6]:33979 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:69205 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); (Minor difference: Regexp.match() just returns boolean true or false, but .split2() is more like Python's .match(). I'm not sure why there's the difference.) ChrisA