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


Groups > comp.lang.python > #69205 > unrolled thread

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

Started byChris Angelico <rosuav@gmail.com>
First post2014-03-28 03:19 +1100
Last post2014-03-28 03:19 +1100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Python language hack for C-style programmers [DO NOT USE!] :-) Chris Angelico <rosuav@gmail.com> - 2014-03-28 03:19 +1100

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

FromChris Angelico <rosuav@gmail.com>
Date2014-03-28 03:19 +1100
SubjectRe: Python language hack for C-style programmers [DO NOT USE!] :-)
Message-ID<mailman.8625.1395937189.18130.python-list@python.org>
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);

(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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web