The Hyper Programming Language |
home | language reference | compiler | hyper on launchpad |
Hyper does not have increment/decrement operators or expressions as they exist in C++ or Java. Instead, it has successor/predecessor expressions and increment/decrement statements. This is to prevent the ambiguous evaluation of some expressions like:
x = i++ * --i // ambiguous in C++ and Java; disallowed in Hyper y = ++j * --j // ambiguous in C++ and Java; allowed and perfectly defined result in Hyper
The first expression is not allowed in Hyper. Hyper does support post-increment (and post-decrement), but you must use it as a separate statement instead of in an expression. And logically, then there is of course no difference anymore between pre- and post-increment.
The second expression is allowed, but it has another result than you might expect. This is not discussed here, but in the section about unary operator expressions.
The general syntax for increment/decrement statements is:
L-value operator
The syntax is very similar to the syntax of a regular assignment, except that the assignment has an R-value and the increment/decrement has not. The rules for the L-value here are the same as the rules for the L-value in an assignment.
An L-value is similar to L-values in other languages. The syntax of an L-value is in general like a postfix operator expression. This means that it consists of an identifier followed by any number of array selection operators, function call operators, and member selection operators. But an L-value must also be changeable, of course, if you want to increment or decrement it. And the type of the L-value must support the operator you use.
So these are the 2 operators that can be used:
Operator | Meaning |
---|---|
++ | Increment |
-- | Decrement |
procedure p() var x & y : int = 5 # variables x and y start with value 5 var p : * int = y # p points to y x++ # increment x; x becomes 6 y-- # decrement y; y becomes 4 p-- # decrement the value p points to; y becomes 3 end