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

2014-03-28 Thread Chris Angelico
On Fri, Mar 28, 2014 at 7:26 PM, Peter Otten <__pete...@web.de> wrote: > One of the most elegant applications of these two principles is to > declare a variable in a condition. Consider: > > if (double d = prim(true)) { > left /= d; > break; > } Okay! Then I withdraw the "or, to my knowled

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

2014-03-28 Thread Peter Otten
Chris Angelico wrote: > On Fri, Mar 28, 2014 at 6:46 PM, Peter Otten <__pete...@web.de> wrote: >> Why would you guess if you can check? Just fire up the interactive >> interpreter^W^W compiler: > > Partly because there's a difference between valid C++ and valid input > to the G++ compiler :) Know

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

2014-03-28 Thread Chris Angelico
On Fri, Mar 28, 2014 at 6:46 PM, Peter Otten <__pete...@web.de> wrote: > Why would you guess if you can check? Just fire up the interactive > interpreter^W^W compiler: Partly because there's a difference between valid C++ and valid input to the G++ compiler :) Knowing that it works with g++ doesn'

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

2014-03-28 Thread Peter Otten
Chris Angelico wrote: > On Fri, Mar 28, 2014 at 12:44 PM, Dave Angel wrote: >>> 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 en

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

2014-03-27 Thread Chris Angelico
On Fri, Mar 28, 2014 at 12:44 PM, Dave Angel wrote: >> 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. Yeah,

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

2014-03-27 Thread Dave Angel
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) > > I

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

2014-03-27 Thread Chris Angelico
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

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

2014-03-27 Thread Chris Angelico
On Fri, Mar 28, 2014 at 3:08 AM, Tim Chase wrote: > So when I stumbled upon this horrific atrocity of language abuse and > scope leakage, I thought I'd share it. > > if [m for m in [regex.match(some_string)] if m]: > do_something(m) > > And presto, assignment in an if-statement. And presto,

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

2014-03-27 Thread Tim Chase
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) So when I stumbled upon this horrific atrocity of language abuse and scope leakage, I thought I'd share it.