Python ++ Operator?
nospam at torek.net
Tue Jul 19 15:08:09 EDT 2011
In article <mailman.1057.1310717193.1164.python-list at python.org>
Chris Angelico <rosuav at gmail.com> wrote:
>I agree that [C's ++ operators are] often confusing (i+++++j) ...
For what it is worth, this has to be written as:
i++ + ++j /* or i+++ ++j */
or similar (e.g., newline after the middle "+" operator) as the
lexer will group adjacent "++" characters into a single "++" operator
whenever it can (the so-called "greedy matching" that regular
expression recognizers are famous for), and only later will the
parser and semantic analysis phases realize that "i++ ++ +j" is
invalid and complain.
>but there are several places where they're handy. ...
>However, Python doesn't work as close to the bare metal, so it
>doesn't have such constructs.
More specifically, Python has appropriate higher-level constructs
that, in effect, maintain "mental invariants" in a better (for some
value of better) way. Instead of:
lst[i++] = val; /* or: *p++ = val; */
which has the effect of appending an item to an array-based list
of items -- the "invariant" here is that i (or p in the pointer
version) always tells you where the place the *next* item -- one
(which also makes sure that there is *room* in the array-based
list, something that requires a separate step in C).
In-Real-Life: Chris Torek, Wind River Systems
Intel require I note that my opinions are not those of WRS or Intel
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: gmail (figure it out) http://web.torek.net/torek/index.html
More information about the Python-list