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


Groups > comp.lang.python > #69234

Re: Python language hack for C-style programmers [DO NOT USE!] :-)

From Dave Angel <davea@davea.name>
Subject Re: Python language hack for C-style programmers [DO NOT USE!] :-)
Date 2014-03-27 21:44 -0400
Organization news.gmane.org
References <20140327110856.14991bb0@bigbox.christie.dr> <CAPTjJmoSEiBEO9fXfwM7mGywty+dT8erBqeu2mpyrxAf12udcw@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.8645.1395970797.18130.python-list@python.org> (permalink)

Show all headers | View raw


 Chris Angelico <rosuav@gmail.com> Wrote in message:
> On Fri, Mar 28, 2014 at 3:08 AM, Tim Chase
> <python.list@tim.thechases.com> 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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Python language hack for C-style programmers [DO NOT USE!] :-) Dave Angel <davea@davea.name> - 2014-03-27 21:44 -0400

csiph-web