dec()
The dec()
function will decrement a named variable, either by one (1
) or by an optionally passed second value.
Syntax:
method dec(var value: Value, number: Value := 1): Value;
Value dec(ref Value value, Value number = 1);
func dec(_ inout value: Value, _ number: Value = 1) -> Value
Value dec(__ref Value value, Value number = 1);
The resulting type is equivalent to the passed value (referred to as Value
above), and can be any Integer, Floating Point or Char type.
Even though the first parameter will be modified, for legacy and compatibility reasons, inc()
and dec()
can be called without marking the parameter as pass-by-reference.
var x := 5;
dec(x); // x is now 4
dec(var x); // x is now 3
int x = 5;
dec(x); // x is now 4
dec(ref x); // x is now 3
var x = 5
dec(x) // x is now 4
dec(&x) // x is now 3
int x = 5;
dec(x); // x is now 4
dec(__ref x); // x is now 3
For C#, Swift and Java, calling dec()
with a single parameter is comparable to using the --
prefix or postfix operator.
int x = 5;
dec(x); // x is now 4
x--; // x is now 3
var x = 5
dec(x) // x is now 4
x-- // x is now 3
int x = 5;
dec(x); // x is now 4
x--; // x is now 3
Operator Overloading
Custom types can add support for dec()
(and Inc()
) by implementing the "Decrement
" operator using each language's support for operator overloading (e.g. using the operator
keyword in Oxygene).
Custom implementations will only support the version of dec()
with a single parameter (i.e. that decrements by the equivalent of "1
", comparable to the --
prefix operator in C#, Swift, Java and Go.
Decrement
operator implementations should adjust the incoming var
/ref
parameter, as well as return its new value as result.