|
Spec-Zone .ru
спецификации, руководства, описания, API
|
Table 6.7. Prefix Unary Operator
| Operator | Meaning | Operand Type | Result Type |
|---|---|---|---|
| - | Negation | - Integer | Integer |
| - Number | Number | ||
| - Duration | Duration | ||
| not | Logical not | not Boolean | Boolean |
| sizeof | Number of elements in a sequence | sizeof Object | Integer |
| reverse | Reverse the elements in a sequence | reverse Object | Object |
| ++ | Add one to the value of the operand, value is updated value | ++ Integer | Integer |
| ++ Number | Number | ||
| -- | Subtract one from the value of the operand, value is updated value | -- Integer | Integer |
| -- Number | Number | ||
| indexof | Current position in the sequence being iterated | n/a | Integer |
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