unaryExpression

Figure 6.27. unaryExpression

unaryExpression

Table 6.7. Prefix Unary Operator

OperatorMeaningOperand TypeResult Type
-Negation- IntegerInteger
- NumberNumber
- DurationDuration
notLogical notnot BooleanBoolean
sizeofNumber of elements in a sequencesizeof ObjectInteger
reverseReverse the elements in a sequencereverse ObjectObject
++Add one to the value of the operand, value is updated value++ IntegerInteger
++ NumberNumber
--Subtract one from the value of the operand, value is updated value-- IntegerInteger
-- NumberNumber
indexofCurrent position in the sequence being iteratedn/aInteger

This example demonstrates the three sequence operators:

def endangered = ['Caribou', 'Ocelot', 'Puma', 'Sei'];
println( endangered );
def flipped = reverse endangered;
println( flipped );
println( sizeof endangered );
for (mammal in endangered) {
   println( 'Mammal #{ indexof mammal } is { mammal }' );
}

The console shows the following:

[ Caribou, Ocelot, Puma, Sei ]
[ Sei, Puma, Ocelot, Caribou ]
4 
Mammal #0 is Caribou 
Mammal #1 is Ocelot 
Mammal #2 is Puma 
Mammal #3 is Sei