Hello all + season's greetings
Up till now gretl has supported only very limited usage of the
increment (++) and deccrement (--) operators. The only acceptable
usage has been in stand-alone expressions (e.g.)
j++ # shorthand for j = j + 1
j-- # shorthand for j = j - 1
for "j" the name of a user-defined scalar variable.
As of today's CVS I'm experimenting with fuller support for
something that is really quite handy in C and similar languages,
namely the ability to embed constructs such as "j++" and "j--" in
more or less arbitrary contexts. For example:
k = j++ # k = current value of j; then increment j
m[j++] = x # assign x to element j of m; increment j
x = foo(j--) # evaluate foo(j); decrement j
Two limitations: (1) only named scalars are supported in this way;
and (2) only the "postfix" variant is supported -- where the scalar
variable in question is incremented or decremented after its value
is taken, unlike C where you can also use "++j" and "--j" to
increment or decrement j before its value is taken.
If people can test this, that would be very helpful.
Since gretl also supports the "unary +" operator there's a
potential ambiguity over what "++" means. The expression
x++2
is equivalent to "x + (+2)" or just "x + 2". However, I believe
we're OK: contexts where "++" should be interpreted in this way can
be distinguished syntactically from contexts where "evaluate then
increment" is warranted. If anyone finds a case where they think
"++" (or "--") is being interpreted wrongly, please let me know.
FYI: it's in CVS but not yet in snapshots.
Allin Cottrell