The function call operator
You can call a function using its name and a comma-separated list of arguments passed to it in parentheses.
The order, number, and type of arguments that you pass a function when invoking it needs to conform to the function's definition.
Even if a function does not take any arguments, the parentheses are required to call it.
The indexing operator
Use square brackets []
as a shorthand of the GetAt
and
SetAt
type methods. On the data types for which these methods are
defined, you can get or set specific values.
For list
s, get or
set values at specific
indexes.
For strings, use the []
operator to access characters at specific
indexes.
However, since the SetAt
method is not defined for string type
objects, you cannot redefine string characters at specific indexes using the
[]
operator
either.
For maps, use the []
operator to get or set the values associated with
specific
keys.
{name: "Moist von Lipwig", age: 33, occupation: "postman"} "Age:", 33 "Occupation:", "man of mystery"
Figure 311. The trace message output of the script above
Note that square brackets can also instantiate list
literals.
The dot operator
Use the .
operator to access members of an object to get or set values of
fields or invoke
methods.
// accessing the New method of the timespan type var a =timespan.New
(4, 3, 2, 1, 60); trace a; // accessing the Minutes field of a timespan tracea.Minutes
; // accessing a member of a map var b = { name: "Rincewind" }; traceb.name
; // access and set a map memberb.name = "Didactylos";
trace b.name;
Logical and comparison operators in order of precedence
Logical OR
The logical OR ||
binary operator takes boolean operands, and returns
the boolean value true
if either operand is true
and
false
otherwise. It has left-to-right associativity, and the
right-hand-side operand is not evaluated if the left-hand-side evaluates to
true
.
true
Logical AND
The logical AND &&
binary operator takes boolean operands, and
returns the boolean value true
if both operands are true
and false
otherwise. It has left-to-right associativity, and the
right-hand-side operand is not evaluated if the left-hand-side evaluates to
false
.
false
Logical NOT
The logical NOT !
unary operator takes a bool
operand and returns its
opposite
bool
.
false
Function call, the indexing, and the dot operators have precedence over logical and comparison operators.
Arithmetic operators in order of precedence
Unary negation
The negative sign -
unary operator takes int
or float
operands and changes
the sign but not the type of their
operands.
"This is dog", -7.89 "This is not dog", 7.89
Multiplication
The multiplication *
and division /
binary operators
take int
or
float
type
operands. If one or both operands is a float
, they return a
float
value, otherwise the result is an
int
.
930
Division
The multiplication *
and division /
binary operators
take int
or
float
type
operands. If one or both operands is a float
, they return a
float
value, otherwise the result is an
int
.
4
Addition
The addition +
binary operator takes int
, float
, string
, dtl
, dtu
, or timespan
values in
specific combinations. The type of the returned value is determined by the particular
combination. When adding the result will be an int unless any of the operands is a
float.
20.56
Addition
is valid for string
s. The result will be a concantenated
string.
"Hello World!"
timespan
values can
be added to dtu
and
dtl
values. The
result will be a dtu
or dtl
depending on the
non-timespan
operand.
2015.10.11. 14:05:31 (Dtu) 2015.10.11. 16:05:31 (Dtl)
timespan
values may
be added to each other, resulting in a third timespan
value.
5.05:05:05.1160000
Subtraction
The subtraction -
binary operator takes int
, float
, string
, dtl
, dtu
, or timespan
values in
specific combinations. The type of the returned value is determined by the particular
combination. When or subtracting numbers, the result will be an int unless any of the
operands is a
float.
-4
Subtraction
is valid for dtu
and
dtl
values. The
result will be a timespan
.
5687.04:17:58.0340000
timespan
values can
be subtracted from dtu
and dtl
values. The result will be a dtu
or
dtl
depending on the non-timespan
operand.
2015.10.03. 10:01:29 (Dtl)
timespan
values may
be subtracted from each other, resulting in a third timespan
value.
3.00:58:57.0040000
The less than <
, greater than >
, less than or equal
to <=
, and greater than or equal to >=
binary
operators take operands of int
, float
, dtl
, or dtu
type and return a bool
value.
"This is true", "true" "This is true also", true
Equality and inequality
The equality ==
and inequality !=
binary operators take
operands of any type, and return a bool
value based on whether the two operands are equal or not.
int
s and
float
s are
treated as the same type for equality
purposes.
"This is true", true; "This is false", false;
Using the equality or inequality operators with operands of differing types results in a runtime error.
Function call, the indexing, and the dot operators have precedence over both logical and arithmetic operators.