Note: information on this page refers to Ceylon 1.2, not to the current release.
--
(decrement) operator
The left-associative, unary --
operators decrement their operand; they
differ in whether the result is assigned before or after the decrement.
Usage
Postfix --
has the operator after the operand:
variable Integer num = 1;
num--;
Prefix --
puts the operator before the operand:
variable Integer num = 1;
--num;
Description
Both operators decrement their operand by one. The difference is that the prefix operator updates its operand and evaluates to the updated value. The postfix operator, in contrast, decrements its operand but evaluates to the value of the operand before the decrement.
Definition
The prefix --
is defined as:
rhs = rhs.predecessor
The postfix --
is defined as:
let (x = lhs, _ = lhs = lhs.predecessor) x
See the language specification for more details.
Polymorphism
The --
operator is polymorphic.
The meaning of --
depends on the
Ordinal
interface.
Type
The result type of the --
operator is the same as the Ordinal
type of its operand.
See also
- ++ (increment) operator
- arithmetic operators in the language specification
- operator precedence in the language specification
- Operator polymorphism and Numeric operator semantics in the Tour of Ceylon