|
|
|
|
|
5. PREDEFINED TYPES
In the following subchapters the predefined types of the standard library are introduced. The operators have, when not stated otherwise, the type described in the subchapter as parameter type and result type. The relations have also the type described in the subchapter as parameter type and a result of type 'boolean'. In the descriptions => is used to show an equivalent expression. 5.1 booleanThe type 'boolean' consists of the two truth values TRUE and FALSE.
Prefix operators:
not Negation
( not TRUE => FALSE,
not FALSE => TRUE )
Infix operators:
and Logical and
( TRUE and TRUE => TRUE,
A and B => FALSE else )
or Inclusive logical or
( FALSE or FALSE => FALSE,
A or B => TRUE else )
boolean conv A Conversion to boolean
( Type of argument A: integer,
boolean conv 0 => FALSE,
boolean conv 1 => TRUE )
boolean parse A Conversion of string to boolean
( Type of argument A: string,
boolean parse "FALSE" => FALSE,
boolean parse "TRUE" => TRUE,
boolean parse "TRUE " => EXCEPTION RANGE_ERROR,
boolean parse "ASDF" => EXCEPTION RANGE_ERROR )
Relations:
=, <>, >, >=, <, <=
( A relation B =>
ord(A) relation ord(B) )
Functions:
ord(A) Ordinal number
( Type of result: integer,
ord(FALSE) => 0, ord(TRUE) => 1 )
succ(A) Successor
( succ(FALSE) => TRUE,
succ(TRUE) => EXCEPTION RANGE_ERROR )
pred(A) Predecessor
( pred(FALSE) => EXCEPTION RANGE_ERROR )
pred(TRUE) => FALSE )
str(A) Conversion to string
( Type of result: string,
str(FALSE) => "FALSE",
str(TRUE) => "TRUE" )
rand(A, B) Random value in the range [A, B]
The random values are uniform distributed.
( rand(A, B) returns a random value such that
A <= rand(A, B) and rand(A, B) <= B holds.
rand(A, A) => A,
rand(TRUE, FALSE) => EXCEPTION RANGE_ERROR )
Statements:
incr(A) Increment
( incr(A) => A:=succ(A) )
decr(A) Decrement
( decr(A) => A:=pred(A) )
The logical operators 'and' and 'or' work strictly left to right. First they evaluate the left operand and then the right operand. When the result of the operation can be determined after evaluation of the left operand the right operand is not evaluated. This can be used to check for a boundary in a boolean expression. Naturally side effects of the right operand of the 'and' and 'or' operator only take place when the operand is executed. Table for the behaviour of different boolean expressions:
Result when the Result when the
Expression first operand first operand
evaluates to FALSE evaluates to TRUE
not A TRUE FALSE
A and B respectively
not((not A)or(not B)) FALSE B
A or B respectively
not((not A)and(not B)) B TRUE
A > B respectively
A and(not B) FALSE not B
A >= B respectively
A or(not B) not B TRUE
A < B respectively
(not A)and B B FALSE
A <= B respectively
(not A)or B TRUE B
not (A and B) respectively
(not A)or(not B) TRUE not B
not (A or B) respectively
(not A)and(not B) not B FALSE
Optimizing boolean expressions: When the result of a boolean expression can be determined at compile time, the expression can be replaced by a constant. Additionally the following equations can be used:
(A or B) and (A or C) = A or (B and C)
(A and B) or (A and C) = A and (B or C)
5.2 integer
The type 'integer' consists of signed integer numbers which are at least 32 bits wide. An 'integer' literal is a sequence of digits which is taken to be decimal. The sequence of digits may be followed by the letter E or e an optional + sign and a decimal exponent. Based numbers can be specified when the sequence of digits is followed by the # character and a sequence of extended digits. The decimal number in front of the # character specifies the base of the number which follows the # character. As base a number between 2 and 36 is allowed. As extended digits the letters A or a can be used for 10, B or b can be used for 11 and so on to Z or z which can be used as 35. Examples of 'integer' literals are:
0 2147483647 1E6 2e+9 16#c0 16#FFFF 8#177777 2#1010101010
The result of an 'integer' operation is undefined when it overflows.
Prefix operators:
+ Identity
- Change sign
! Factorial
Infix operators:
+ Addition
- Subtraction
* Multiplication
div Integer division truncated towards zero
( A div B => trunc(flt(A) / flt(B)),
A div 0 => EXCEPTION NUMERIC_ERROR )
rem Reminder of integer division div
( A rem B => A - (A div B) * B,
A rem 0 => EXCEPTION NUMERIC_ERROR )
mdiv Integer division truncated towards negative infinity
( A mdiv B => round(floor(flt(A) / flt(B))),
A mdiv 0 => EXCEPTION NUMERIC_ERROR )
mod Reminder of integer division mdiv
( A mod B => A - (A mdiv B) * B,
A mod 0 => EXCEPTION NUMERIC_ERROR )
** Power
( A ** B is okay for B >= 0,
A ** 0 => 1,
1 ** B => 1,
A ** -1 => EXCEPTION NUMERIC_ERROR )
A << B Shift left
( A << B is okay for B >= 0 and B <= 31,
A << B => A * 2_ ** B,
A << 0 => A )
A >> B Arithmetic shift right
( A >> B is okay for B >= 0 and B <= 31,
A >> B => A mdiv 2_ ** B for B <= 30,
A >> B => C for A >= 0 holds: C >= 0
A >> B => C for A < 0 holds: C < 0
A >> B => 0 for A >= 0 and B > ord(log2(A)),
A >> B => -1 for A < 0 and B > ord(log2(-A)),
A >> 0 => A )
! Binomial coefficient
( A ! B => !A div (!B * !(A - B)) )
lpad0 Left padding with zeros
( 123 lpad0 8 => "00000123",
123 lpad0 4 => "0123",
123 lpad0 3 => "123",
123 lpad0 2 => "123",
123 lpad0 -8 => "123",
-12 lpad0 4 => "-012",
-12 lpad0 3 => "-12",
-12 lpad0 2 => "-12" )
integer conv A Identity
( integer conv A => A )
integer parse A Conversion of string to integer
( Type of argument A: string,
integer parse "123" => 123,
integer parse "-123" => -123,
integer parse "+5" => 5,
integer parse " 1" => EXCEPTION RANGE_ERROR,
integer parse "10 " => EXCEPTION RANGE_ERROR,
integer parse "ASDF" => EXCEPTION RANGE_ERROR )
Relations:
=, <>, <, <=, >, >=
Functions:
ord(A) Identity
succ(A) Successor
( succ(A) => A+1 )
pred(A) Predecessor
( pred(A) => A-1 )
abs(A) Absolute value
odd(A) Odd value
( Type of result: boolean )
str(A) Conversion to string
( Type of result: string )
literal(A) Conversion to a literal
( Type of result: string,
literal(A) => str(A) )
sqrt(A) Integer square root
( sqrt(A) is okay for A >= 0
sqrt(A) => trunc(sqrt(flt(A))),
sqrt(-1) => EXCEPTION NUMERIC_ERROR )
log2(A) Truncated base 2 logarithm
( log2(A) returns the position of the
highest bit set. It is defined for A >= 0
log2(2 ** A) = A for A >= 0,
log2(0) => -1,
log2(1) => 0,
log2(2) => 1,
log2(-1) => EXCEPTION NUMERIC_ERROR )
bitLength(A) Number of bits in the minimal two's-complement
representation, excluding the sign bit.
( bitLength(A) => succ(log2(A)) for A >= 0,
bitLength(A) => succ(log2(pred(-A))) for A < 0 )
lowestSetBit(A) Index of the lowest-order one bit
For A <> 0 this is equal to to number of
lowest-order zero bits.
( A >> B << B = A for A <> 0 and B = lowestSetBit(A),
lowestSetBit(0) => -1,
lowestSetBit(1) => 0,
lowestSetBit(2) => 1 )
rand(A, B) Random number in the range [A, B]
The random values are uniform distributed.
( rand(A, B) returns a random number such that
A <= rand(A, B) and rand(A, B) <= B holds.
rand(A, A) => A,
rand(1, 0) => EXCEPTION RANGE_ERROR )
compare(A, B) Compare function
( compare(1, 2) => -1,
compare(5, 5) => 0,
compare(8, 7) => 1 )
hashCode(A) Hash function
Statements:
A +:= B Increment A by B
( A +:= B => A := A + B )
A -:= B Decrement A by B
( A -:= B => A := A - B )
A *:= B Multiplying copy
( A *:= B => A := A * B )
A <<:= B Shift left copy
( A <<:= B => A := A << B )
A >>:= B Shift right copy
( A >>:= B => A := A >> B )
incr(A) Increment with 1
( incr(A) => A +:= 1 )
decr(A) Decrement with 1
( decr(A) => A -:= 1 )
For the operations 'div' and 'rem' holds for all A:
(A div B) * B + A rem B = A when B <> 0
-A div B = -(A div B) when B <> 0
-A rem B = -(A rem B) when B <> 0
A rem B >= 0 and A rem B < abs(B) when B <> 0 and A >= 0
A rem B <= 0 and A rem B > -abs(B) when B <> 0 and A <= 0
For the operations 'mdiv' and 'mod' holds for all A:
(A mdiv B) * B + A mod B = A when B <> 0
-A mdiv B = A mdiv -B when B <> 0
-A mod -B = -(A mod B) when B <> 0
A mod B >= 0 and A mod B < B when B > 0
A mod B <= 0 and A mod B > B when B < 0
For the operation 'mdiv' holds:
A mdiv B = A div B - 1 when A and B have different
signs and A rem B <> 0 holds.
A mdiv B = A div B when A and B have the same
sign or A rem B = 0 holds.
A mdiv B = (A - 1) div B - 1 when A > 0 and B < 0 holds.
A mdiv B = (A + 1) div B - 1 when A < 0 and B > 0 holds.
For the operation 'mod' holds:
A mod B = A rem B + B when A and B have different
signs and A rem B <> 0 holds.
A mod B = A rem B when A and B have the same
sign or A rem B = 0 holds.
Table for the behaviour of 'div', 'rem', 'mdiv' and 'mod':
A B A div B A rem B A mdiv B A mod B
5 3 1 2 1 2
4 3 1 1 1 1
3 3 1 0 1 0
2 3 0 2 0 2
1 3 0 1 0 1
0 3 0 0 0 0
-1 3 0 -1 -1 2
-2 3 0 -2 -1 1
-3 3 -1 0 -1 0
-4 3 -1 -1 -2 2
-5 3 -1 -2 -2 1
A B A div B A rem B A mdiv B A mod B
5 -3 -1 2 -2 -1
4 -3 -1 1 -2 -2
3 -3 -1 0 -1 0
2 -3 0 2 -1 -1
1 -3 0 1 -1 -2
0 -3 0 0 0 0
-1 -3 0 -1 0 -1
-2 -3 0 -2 0 -2
-3 -3 1 0 1 0
-4 -3 1 -1 1 -1
-5 -3 1 -2 1 -2
For the 'sqrt' function holds (when A >= 0):
sqrt(A) * sqrt(A) <= A and
(sqrt(A) + 1) * (sqrt(A) + 1) > A
5.3 bigInteger
The type 'bigInteger' describes signed integer numbers of unlimited size. The literals of the type 'bigInteger' are sequences of digits followed by an underscore character (for example 1_ ). Although 'bigInteger' operations cannot overflow, it can happen that there is not enough memory to represent a 'bigInteger' value. In this case the exception 'MEMORY_ERROR' is raised.
Prefix operators:
+ Identity
- Change sign
Infix operators:
+ Addition
- Subtraction
* Multiplication
div Integer division truncated towards zero
( A div B => trunc(A / B),
A div 0_ => EXCEPTION NUMERIC_ERROR )
rem Reminder of integer division div
( A rem B => A - (A div B) * B,
A rem 0_ => EXCEPTION NUMERIC_ERROR )
mdiv Integer division truncated towards negative infinity
( A mdiv B => floor(A / B),
A mdiv 0_ => EXCEPTION NUMERIC_ERROR )
mod Reminder of integer division mdiv
( A mod B => A - (A mdiv B) * B,
A mod 0_ => EXCEPTION NUMERIC_ERROR )
A ** B Power
( Type of argument B: integer,
A ** B is okay for B >= 0,
A ** 0 => 1_,
1_ ** B => 1_,
A ** -1 => EXCEPTION NUMERIC_ERROR )
A << B Shift left
( Type of argument B: integer,
A << B is okay for B >= 0,
A << B => A * 2_ ** B,
A << 0 => A,
A << -1 => EXCEPTION NUMERIC_ERROR )
A >> B Arithmetic shift right
( Type of argument B: integer,
A >> B is okay for B >= 0,
A >> B => A mdiv 2_ ** B,
A >> B => C for A >= 0_ holds: C >= 0_
A >> B => C for A < 0_ holds: C < 0_
A >> B => 0_ for A >= 0_ and B > ord(log2(A)),
A >> B => -1_ for A < 0_ and B > ord(log2(-A)),
A >> 0 => A,
A >> -1 => EXCEPTION NUMERIC_ERROR )
bigInteger conv A Conversion to bigInteger
( Type of argument A: integer,
bigInteger conv A => A )
bigInteger parse A Conversion of string to integer
( Type of argument A: string,
bigInteger parse "123" => 123_,
bigInteger parse "-123" => -123_,
bigInteger parse " 1" => EXCEPTION RANGE_ERROR,
bigInteger parse "+5" => EXCEPTION RANGE_ERROR,
bigInteger parse "10 " => EXCEPTION RANGE_ERROR,
bigInteger parse "ASDF" => EXCEPTION RANGE_ERROR )
Relations:
=, <>, <, <=, >, >=
Functions:
ord(A) Ordinal number
( Type of result: integer )
ord(99999999999999999999_) => EXCEPTION RANGE_ERROR )
succ(A) Successor
( succ(A) => A+1_ )
pred(A) Predecessor
( pred(A) => A-1_ )
abs(A) Absolute value
odd(A) Odd value
( Type of result: boolean )
str(A) Conversion to string
( Type of result: string )
sqrt(A) Integer square root
( sqrt(A) is okay for A >= 0_
sqrt(A) => trunc(sqrt(flt(A))),
sqrt(-1_) => EXCEPTION NUMERIC_ERROR )
log2(A) Truncated base 2 logarithm
( log2(A) returns the position of the
highest bit set. It is defined for A >= 0
log2(2_ ** A) = A for A >= 0,
log2(0_) => -1_,
log2(1_) => 0_,
log2(2_) => 1_,
log2(-1) => EXCEPTION NUMERIC_ERROR )
gcd(A, B) Greatest common divisor of A and B.
( gcd(A, B) = gcd(B, A),
gcd(A, B) = gcd(-A, B),
gcd(A, 0) = abs(A) )
bitLength(A) Number of bits in the minimal two's-complement
representation, excluding the sign bit.
( Type of result: integer,
bitLength(A) => ord(succ(log2(A))) for A >= 0_,
bitLength(A) => ord(succ(log2(pred(-A)))) for A < 0_ )
lowestSetBit(A) Index of the lowest-order one bit
For A <> 0_ this is equal to to number of
lowest-order zero bits.
( Type of result: integer,
A >> B << B = A for A <> 0_ and B = lowestSetBit(A),
lowestSetBit(0_) => -1,
lowestSetBit(1_) => 0,
lowestSetBit(2_) => 1 )
rand(A, B) Random number in the range [A, B]
The random values are uniform distributed.
( rand(A, B) returns a random number such that
A <= rand(A, B) and rand(A, B) <= B holds.
rand(A, A) => A,
rand(1_, 0_) => EXCEPTION RANGE_ERROR )
compare(A, B) Compare function
( Type of result: integer,
compare(1_, 2_) => -1,
compare(5_, 5_) => 0,
compare(8_, 7_) => 1 )
hashCode(A) Hash function
( Type of result: integer )
Statements:
A +:= B Increment A by B
( A +:= B => A := A + B )
A -:= B Decrement A by B
( A -:= B => A := A - B )
A *:= B Multiplying copy
( A *:= B => A := A * B )
A <<:= B Shift left copy
( A <<:= B => A := A << B )
A >>:= B Shift right copy
( A >>:= B => A := A >> B )
incr(A) Increment with 1
( incr(A) => A +:= 1_ )
decr(A) Decrement with 1
( decr(A) => A -:= 1_ )
For the operations 'div' and 'rem' holds for all A:
(A div B) * B + A rem B = A when B <> 0_
-A div B = -(A div B) when B <> 0_
-A rem B = -(A rem B) when B <> 0_
A rem B >= 0_ and A rem B < abs(B) when B <> 0_ and A >= 0_
A rem B <= 0_ and A rem B > -abs(B) when B <> 0_ and A <= 0_
For the operations 'mdiv' and 'mod' holds for all A:
(A mdiv B) * B + A mod B = A when B <> 0_
-A mdiv B = A mdiv -B when B <> 0_
-A mod -B = -(A mod B) when B <> 0_
A mod B >= 0_ and A mod B < B when B > 0_
A mod B <= 0_ and A mod B > B when B < 0_
For the operation 'mdiv' holds:
A mdiv B = A div B - 1_ when A and B have different
signs and A rem B <> 0_ holds.
A mdiv B = A div B when A and B have the same
sign or A rem B = 0_ holds.
A mdiv B = (A - 1_) div B - 1_ when A > 0_ and B < 0_ holds.
A mdiv B = (A + 1_) div B - 1_ when A < 0_ and B > 0_ holds.
For the operation 'mod' holds:
A mod B = A rem B + B when A and B have different
signs and A rem B <> 0_ holds.
A mod B = A rem B when A and B have the same
sign or A rem B = 0_ holds.
Table for the behaviour of 'div', 'rem', 'mdiv' and 'mod':
A B A div B A rem B A mdiv B A mod B
5_ 3_ 1_ 2_ 1_ 2_
4_ 3_ 1_ 1_ 1_ 1_
3_ 3_ 1_ 0_ 1_ 0_
2_ 3_ 0_ 2_ 0_ 2_
1_ 3_ 0_ 1_ 0_ 1_
0_ 3_ 0_ 0_ 0_ 0_
-1_ 3_ 0_ -1_ -1_ 2_
-2_ 3_ 0_ -2_ -1_ 1_
-3_ 3_ -1_ 0_ -1_ 0_
-4_ 3_ -1_ -1_ -2_ 2_
-5_ 3_ -1_ -2_ -2_ 1_
A B A div B A rem B A mdiv B A mod B
5_ -3_ -1_ 2_ -2_ -1_
4_ -3_ -1_ 1_ -2_ -2_
3_ -3_ -1_ 0_ -1_ 0_
2_ -3_ 0_ 2_ -1_ -1_
1_ -3_ 0_ 1_ -1_ -2_
0_ -3_ 0_ 0_ 0_ 0_
-1_ -3_ 0_ -1_ 0_ -1_
-2_ -3_ 0_ -2_ 0_ -2_
-3_ -3_ 1_ 0_ 1_ 0_
-4_ -3_ 1_ -1_ 1_ -1_
-5_ -3_ 1_ -2_ 1_ -2_
For the 'sqrt' function holds (when A >= 0_):
sqrt(A) * sqrt(A) <= A and
(sqrt(A) + 1_) * (sqrt(A) + 1_) > A
5.4 rational
The type 'rational' consists of rational numbers represented with an 'integer' numerator and an 'integer' denominator. The values of the type 'rational' are finite and periodical decimal numbers. Rational literals do not exist. The result of a 'rational' operation is undefined when it overflows.
Prefix operators:
+ Identity
- Change sign
Infix operators:
+ Addition
- Subtraction
* Multiplication
/ Division
** Power
( rational ** integer )
rational parse A Conversion of string to rational
( Type of argument A: string )
Relations:
=, <>, <, <=, >, >=
Functions:
abs(A) Absolute value
rat(A) Conversion to rational
( Type of argument A: integer,
rat(1) => 1.0 )
floor(A) Truncation towards negative infinity
( Type of result: integer,
floor( 1.8)=> 1, floor( 1.0)=> 1,
floor(-1.0)=>-1, floor(-1.8)=>-2 )
ceil(A) Rounding up towards positive infinity
( Type of result: integer,
ceil( 1.2)=> 2, ceil( 1.0)=> 1,
ceil(-1.0)=>-1, ceil(-1.2)=>-1 )
trunc(A) Truncation towards zero
( Type of result: integer,
trunc( 1.8)=> 1, trunc( 1.0)=> 1,
trunc(-1.0)=>-1, trunc(-1.8)=>-1 )
round(A) Round towards zero
( Type of result: integer,
round(0.5)=>1, round(-0.5)=>-1,
round(0.4)=>0, round(-0.4)=>0 )
str(A) Conversion to string
( Type of result: string )
compare(A, B) Compare function
( Type of result: integer,
compare(1.9, 2.0) => -1,
compare(5.2, 5.2) => 0,
compare(8.0, 7.9) => 1 )
hashCode(A) Hash function
( Type of result: integer )
Statements:
A +:= B Increment A by B
( A +:= B => A := A + B )
A -:= B Decrement A by B
( A -:= B => A := A - B )
A *:= B Multiplying copy
( A *:= B => A := A * B )
All calculations with 'rational' numbers are done exact. (Without any rounding) 5.5 bigRationalThe type 'bigRational' consists of rational numbers represented with an 'bigInteger' numerator and an 'bigInteger' denominator. The values of the type 'bigRational' are finite and periodical decimal numbers. BigRational literals do not exist. Although 'bigRational' operations cannot overflow, it can happen that there is not enough memory to represent a 'bigRational' value. In this case the exception 'MEMORY_ERROR' is raised.
Prefix operators:
+ Identity
- Change sign
Infix operators:
+ Addition
- Subtraction
* Multiplication
/ Division
/ Division of two bigInteger values
( Left argument: bigInteger,
Right argument: bigInteger )
** Power
( bigRational ** integer )
bigRational parse A Conversion of string to bigRational
( Type of argument A: string )
Relations:
=, <>, <, <=, >, >=
Functions:
abs(A) Absolute value
rat(A) Conversion to bigRational
( Type of argument A: bigInteger,
rat(1) => 1.0 )
floor(A) Truncation towards negative infinity
( Type of result: bigInteger,
floor( 1.8)=> 1, floor( 1.0)=> 1,
floor(-1.0)=>-1, floor(-1.8)=>-2 )
ceil(A) Rounding up towards positive infinity
( Type of result: bigInteger,
ceil( 1.2)=> 2, ceil( 1.0)=> 1,
ceil(-1.0)=>-1, ceil(-1.2)=>-1 )
trunc(A) Truncation towards zero
( Type of result: bigInteger,
trunc( 1.8)=> 1, trunc( 1.0)=> 1,
trunc(-1.0)=>-1, trunc(-1.8)=>-1 )
round(A) Round towards zero
( Type of result: bigInteger,
round(0.5)=>1, round(-0.5)=>-1,
round(0.4)=>0, round(-0.4)=>0 )
str(A) Conversion to string
( Type of result: string )
compare(A, B) Compare function
( Type of result: integer,
compare(1.9, 2.0) => -1,
compare(5.2, 5.2) => 0,
compare(8.0, 7.9) => 1 )
hashCode(A) Hash function
( Type of result: integer )
Statements:
A +:= B Increment A by B
( A +:= B => A := A + B )
A -:= B Decrement A by B
( A -:= B => A := A - B )
A *:= B Multiplying copy
( A *:= B => A := A * B )
All calculations with 'bigRational' numbers are done exact. (Without any rounding) 5.6 floatThe type 'float' consists of single precision floating point numbers.
Constants:
Infinity Positive infinity
NaN Not-a-Number
Prefix operators:
+ Identity
- Change sign
Infix operators:
+ Addition
- Subtraction
* Multiplication
/ Division
( A / 0.0 => Infinity for A > 0.0,
A / 0.0 => -Infinity for A < 0.0,
0.0 / 0.0 => NaN )
** Power
( A ** B is okay for A > 0.0,
A ** B => okay for A < 0.0 and B is integer,
A ** B => NaN for A < 0.0 and B is not integer,
A ** 0.0 => 1.0,
0.0 ** B => 0.0 for B > 0.0,
0.0 ** 0.0 => 1.0,
0.0 ** B => Infinity for B < 0.0 )
** Power
( Type of right operand: integer
A ** B is okay for A > 0.0,
A ** B is okay for A < 0.0,
A ** 0 => 1.0,
0.0 ** B => 0.0 for B > 0,
0.0 ** 0 => 1.0,
0.0 ** B => Infinity for B < 0 )
digits Conversion to string with specified precision
( Type of right operand: integer,
Type of result: string,
3.1415 digits 2 => "3.14",
Infinity digits A => "Infinity",
-Infinity digits A => "-Infinity",
NaN digits A => "NaN" )
float parse A Conversion of string to float
( Type of argument A: string )
Relations:
=, <>, <, <=, >, >=
Functions:
abs(A) Absolute value
flt(A) Conversion to float
( Type of argument A: integer,
flt(1) => 1.0 )
floor(A) Truncation towards negative infinity
( floor( 1.8)=> 1.0, floor( 1.0)=> 1.0,
floor(-1.0)=>-1.0, floor(-1.2)=>-2.0,
floor( 0.9)=> 0.0, floor(-0.1)=>-1.0 )
ceil(A) Rounding up towards positive infinity
( ceil( 1.2)=> 2.0, ceil( 1.0)=> 1.0,
ceil(-1.8)=>-1.0, ceil(-1.0)=>-1.0,
ceil( 0.1)=> 1.0, ceil(-0.9)=> 0.0 )
trunc(A) Truncation towards zero
( Type of result: integer,
trunc( 1.8)=> 1, trunc( 1.0)=> 1,
trunc(-1.8)=>-1, trunc(-1.0)=>-1,
trunc( 0.9)=> 0, trunc(-0.9)=> 0 )
round(A) Round towards zero
( Type of result: integer,
round(1.5)=>2, round(-1.5)=>-2,
round(0.5)=>1, round(-0.5)=>-1,
round(0.4)=>0, round(-0.4)=>0 )
str(A) Conversion to string
( Type of result: string,
str(Infinity) => "Infinity",
str(-Infinity) => "-Infinity",
str(NaN) => "NaN" )
isnan(A) Check if A is Not-a-Number
sin(A) Sine
cos(A) Cosine
tan(A) Tangent
exp(A) Exponential function
log(A) Natural logarithm
( log(A) is okay for A > 0.0,
log(0.0) => -Infinity,
log(-1.0) => NaN )
log10(A) Base 10 logarithm
( log10(A) is okay for A > 0.0,
log10(0.0) => -Infinity,
log10(-1.0) => NaN )
sqrt(A) Square root
( sqrt(A) is okay for A >= 0.0,
sqrt(-1.0) => NaN )
asin(A) Inverse sine
( asin(A) is okay for A >= -1.0 and A <= 1.0,
asin(2.0) => NaN )
acos(A) Inverse cosine
( acos(A) is okay for A >= -1.0 and A <= 1.0,
acos(2.0) => NaN )
atan(A) Inverse tangent
atan2(A, B) Inverse tangent of A / B
sinh(A) Hyperbolic sine
cosh(A) Hyperbolic cosine
tanh(A) Hyperbolic tangent
rand(A, B) Random number in the range [A, B]
The random values are uniform distributed.
( rand(A, B) returns a random number such that
A <= rand(A, B) and rand(A, B) <= B holds.
rand(A, A) => A,
rand(1.0, 0.0) => EXCEPTION RANGE_ERROR )
compare(A, B) Compare function
( Type of result: integer,
compare(1.9, 2.1) => -1,
compare(5.3, 5.3) => 0,
compare(7.8, 7.7) => 1 )
hashCode(A) Hash function
( Type of result: integer )
Statements:
A +:= B Increment A by B
( A +:= B => A := A + B )
A -:= B Decrement A by B
( A -:= B => A := A - B )
A *:= B Multiplying copy
( A *:= B => A := A * B )
A /:= B Dividing copy
( A /:= B => A := A / B )
5.7 complex
The type 'complex' consists of complex numbers represented with an 'float' real part and an 'float' imaginary part. Complex literals do not exist.
Prefix operators:
+ Identity
- Change sign
Infix operators:
+ Addition
- Subtraction
* Multiplication
/ Division
( A / complex(0.0) => complex(NaN, NaN) )
** Power
( Type of right operand: integer
A ** B is okay for A > complex(0.0),
A ** B is okay for A < complex(0.0),
A ** 0 => complex(1.0),
complex(0.0) ** B => complex(0.0) for B > 0,
complex(0.0) ** 0 => complex(1.0),
complex(0.0) ** B => complex(Infinity, NaN) for B < 0 )
digits Conversion to string with specified precision
( Type of right operand: integer,
Type of result: string,
complex(3.1415) digits 2 => "3.14+0.00i" )
complex parse A Conversion of string to complex
( Type of argument A: string )
Relations:
=, <>
Functions:
abs(A) Absolute value
( Type of result: float )
sqrAbs(A) Square of absolute value
( Type of result: float )
arg(A) Argument (=angle of the polar form of A)
( Type of result: float )
complex(A, B) Return a complex number from its real and imaginary part
( Type of argument A: float,
Type of argument B: float )
complex(A) Return a complex number from its real part
( Type of argument A: float )
polar(A, B) Return a complex number from polar coordinates
( Type of argument A: float,
Type of argument B: float )
str(A) Conversion to string
( Type of result: string,
str(complex(1.125)) => "1.125+0.0i" )
Statements:
A +:= B Increment A by B
( A +:= B => A := A + B )
A -:= B Decrement A by B
( A -:= B => A := A - B )
A *:= B Multiplying copy
( A *:= B => A := A * B )
A /:= B Dividing copy
( A /:= B => A := A / B )
5.8 char
The type 'char' describes UNICODE characters. The 'char' values use the UTF-32 encoding. In the source file a character literal is written as UTF-8 UNICODE character enclosed in single quotes. In order to represent nonprintable characters and certain printable characters the following escape sequences may be used.
audible alert BEL \a backslash (\) \\
backspace BS \b apostrophe (') \'
escape ESC \e double quote (") \"
formfeed FF \f
newline NL (LF) \n control-A \A
carriage return CR \r ...
horizontal tab HT \t control-Z \Z
vertical tab VT \v
Additionally the following escape sequence can be used:
Examples of character literals are:
'a' ' ' '\n' '!' '\\' '2' '"' '\"' '\'' '\8\'
To use characters beyond ASCII (which is a subset of UNICODE) in the source file make sure that the editor uses UTF-8 encoded characters.
Infix operators:
char conv A Conversion to char
( Type of argument A: integer,
char conv 65 => 'A' )
char parse A Conversion of string to char
( Type of argument A: string )
Relations:
=, <>, <, <=, >, >=
Functions:
ord(A) Ordinal number
( Type of result: integer )
chr(A) Conversion to char
( Type of argument: integer )
succ(A) Successor
( succ(A)=>chr(succ(ord(A))) )
pred(A) Predecessor
( pred(A)=>chr(pred(ord(A))) )
str(A) Conversion to string
( Type of result: string,
str('A') => "A" )
literal(A) Conversion to a literal
( Type of result: string,
literal('A') => "'A'" )
upper(A) Conversion to upper case character
( upper('A') => 'A' )
( upper('z') => 'Z' )
lower(A) Conversion to lower case character
( lower('A') => 'a' )
( lower('z') => 'z' )
rand(A, B) Random character in the range [A, B]
The random values are uniform distributed.
( rand(A, B) returns a random character such that
A <= rand(A, B) and rand(A, B) <= B holds.
rand(A, A) => A,
rand('B', 'A') => EXCEPTION RANGE_ERROR )
compare(A, B) Compare function
( Type of result: integer,
compare('A', 'B') => -1,
compare('A', 'A') => 0,
compare('B', 'A') => 1 )
hashCode(A) Hash function
( Type of result: integer )
Statements:
incr(A) Increment
( incr(A) => A := succ(A) )
decr(A) Decrement
( decr(A) => A := pred(A) )
5.9 string
The type 'string' describes sequences of UNICODE characters (including the empty string). The characters in the 'string' use the UTF-32 encoding. Strings are not '\0\' terminated and therefore can also contain binary data. Although 'string's are allowed to grow very big, it can happen that there is not enough memory to represent a 'string' value. In this case the exception 'MEMORY_ERROR' is raised. In the source file a string literal is a sequence of UTF-8 UNICODE characters surrounded by double quotes. To represent control characters and certain other characters in strings the same escape sequences as for character literals may be used. E.g.: Quotation characters (") inside strings can be represented by preceding them with a backslash ( \" ). Additionally there is the following possibility:
Examples of string literals are:
"" " " "\"" "'" "String" "CAN\"T !"
To use characters beyond ASCII (which is a subset of UNICODE) in the source file make sure that the editor uses UTF-8 encoded characters.
Infix operators:
& String concatenation
( "All " & "OK" => "All OK" )
<& String concatenation with weak priority
Overloaded for various types with 'enable_io'
( write("i=" <& i digits 2 len 6 <& " $"); )
mult String multiplication
( Type of right operand: integer,
"LA" mult 3 => "LALALA",
"WORD" mult 0 => "",
"ANY" mult -1 => EXCEPTION RANGE_ERROR )
lpad Left padding with spaces
( Type of right operand: integer,
"HELLO" lpad 8 => " HELLO",
"HELLO" lpad 6 => " HELLO",
"HELLO" lpad 5 => "HELLO",
"HELLO" lpad 4 => "HELLO",
"HELLO" lpad 0 => "HELLO",
"HELLO" lpad -8 => "HELLO" )
lpad0 Left padding with spaces
( Type of right operand: integer,
"12" lpad0 5 => "00012",
"12" lpad0 3 => "012",
"12" lpad0 2 => "12",
"12" lpad0 1 => "12",
"12" lpad0 0 => "12",
"12" lpad0 -5 => "12" )
rpad Right padding with spaces
( Type of right operand: integer,
"HELLO" rpad 8 => "HELLO ",
"HELLO" rpad 6 => "HELLO ",
"HELLO" rpad 5 => "HELLO",
"HELLO" rpad 4 => "HELLO",
"HELLO" rpad 0 => "HELLO",
"HELLO" rpad -8 => "HELLO" )
string parse A Identity
Indices:
[ A ] Access one character
( Type of argument A: integer,
Type of result: char,
A[1] => First character,
A[length(A)] => Last character,
A[0] => EXCEPTION RANGE_ERROR,
A[succ(length(A))] => EXCEPTION RANGE_ERROR )
[ A .. B ] Access a substring from position A to B
( Type of arguments A and B: integer )
[ A len B ] Access a substring from position A with length B
( Type of arguments A and B: integer )
[ A .. ] Access a substring beginning at position A
( Type of argument A: integer )
[ .. A ] Access a substring ending at position A
( Type of argument A: integer )
Relations:
=, <>, <, <=, >, >=
Functions:
length(A) Length of string
( Type of result: integer,
length("") => 0 )
pos(A,B) First position of char B in string A
( Type of argument B: char,
Type of result: integer,
pos("ABCABC",'B')=>2,
pos("XYZ",'A')=>0 )
pos(A,B) First position of string B in string A
( Type of result: integer,
pos("ABCDE ABCDE","BC")=>2,
pos("XYZXYZ","ZYX")=>0,
pos("123456789","")=>0 )
pos(A,B,C) First position of char B in string A
The search starts at position C of string A
( Type of argument B: char,
Type of argument C: integer,
Type of result: integer,
pos("ABCABC",'B', 3)=>5,
pos("XYZYX",'Z', 4)=>0,
pos("12345",'3', 7)=>0 )
pos(A,B,C) First position of string B in string A
The search starts at position C of string A
( Type of argument C: integer,
Type of result: integer,
pos("ABCDE ABCDE","BC", 3)=>8,
pos("XYZXYZ","ZXY", 4)=>0,
pos("12345","34", 7)=>0 )
pos("123456789","", 2)=>0 )
rpos(A,B) Last position of char B in string A
( Type of argument B: char,
Type of result: integer,
rpos("ABCABC",'B')=>5,
rpos("XYZ",'A')=>0 )
rpos(A,B) Last position of string B in string A
( Type of result: integer,
rpos("ABCDE ABCDE","BC")=>8,
rpos("XYZXYZ","ZYX")=>0,
rpos("123456789","")=>0 )
replace(A,B,C) Replace all occurrences of string B in
string A by string C
( replace("old gold", "old", "one")=>
"one gone" )
split(A,B) Split A into strings delimited by B
( Type of argument B: char,
Type of result: array string,
split("", ':') => [](""),
split(":", ':') => []("", ""),
split("15:30", ':') => []("15", "30") )
split(A,B) Split A into strings delimited by B
( Type of result: array string,
split("", "") => [](""),
split("ABC", "") => []("ABC"),
split("", "; ") => [](""),
split("writeln; readln;", "; ") => []("writeln", "readln;") )
join(A,B) Join the elements of A together with B's between them
( Type of argument A: array string,
Type of argument B: char,
join([]("This", "is", "a", "test"), ' ') => "This is a test" )
join(A,B) Join the elements of A together with B's between them
( Type of argument A: array string,
Type of argument B: string,
join([]("pro", "gram"), "") => "program" )
trim(A) Removes leading and trailing spaces and control chars
( trim(" /n xyz /r") = "xyz" )
str(A) Conversion to string
( Type of result: string,
str(A) => A )
literal(A) Conversion to a literal
( Type of result: string,
literal("ABC") => "\"ABC\"",
literal("O' \"X\"") => "\"O\' \\\"X\\\"\"" )
upper(A) Conversion to upper case characters
( upper("Upper")=>"UPPER" )
lower(A) Conversion to lower case characters
( lower("Lower")=>"lower" )
compare(A, B) Compare function
( Type of result: integer,
compare("ABC", "ABCD")=>-1,
compare("ABC", "ABC")=>0,
compare("ABCD", "ABCC")=>1 )
hashCode(A) Hash function
( Type of result: integer )
Statements:
A &:= B Append B to A
( A &:= B => A := A & B )
A @:= [B] C Assign C to element B of string A
( Type of argument B: integer,
Type of argument C: char,
A @:= [B] C =>
A := A[..pred(B)] & str(C) & A[succ(B)..],
A @:= [0] 'x' => EXCEPTION RANGE_ERROR,
A @:= [succ(length(A))] 'x' => EXCEPTION RANGE_ERROR )
5.10 array
The type 'array baseType' describes sequences of identical elements of a 'baseType'. (including the empty sequence). For example: 'array integer' describes arrays of integer elements. The minimal and maximal indices of an array are part of the value and can be obtained with the functions 'minIdx' and 'maxIdx'. There are functions which generate arrays with the default minimal index of 1 and other functions which generate arrays with the minimal index taken from a parameter.
Literal:
[] (elem1, elem2) Create an array with the given elements
The starting index of the array is 1.
[0] (elem1, elem2) Create an array with the given elements
The starting index of the array is 0.
Infix operators:
& Array concatenation
times Array generation
( Left operand: integer,
Right operand: baseType,
A times B Generates an 'array baseType'
with A elements of B,
(1 times B)[1] => B
-1 times B => EXCEPTION RANGE_ERROR )
[ A .. B ] times C Array generation
( Type of arguments A and B: integer )
Type of argument C: baseType,
[ A .. B ] times C Generates an 'array baseType'
with pred(B - A) elements of C,
[ -1 .. -2 ] times B => empty array,
[ -1 .. -3 ] times B => EXCEPTION RANGE_ERROR )
Indices:
[ A ] Access one array element
( Type of argument A: integer,
Type of result: baseType,
A[minIdx(A)] => First element,
A[maxIdx(A)] => Last element,
A[pred(minIdx(A))] => EXCEPTION RANGE_ERROR,
A[succ(maxIdx(A))] => EXCEPTION RANGE_ERROR )
[ A .. B ] Access a sub array
( Type of arguments A and B: integer )
[ A .. ] Access a sub array beginning at position A
( Type of argument A: integer )
[ .. A ] Access a sub array ending at position A
( Type of argument A: integer )
Relations:
=, <>
Functions:
length(A) Length of array
( Type of result: integer,
length(A) = succ(maxIdx(A) - minIdx(A)),
length(0 times TRUE) => 0,
length(5 times TRUE) => 5 )
minIdx(A) Minimal index of array
( Type of result: integer,
minIdx(3 times TRUE) => 1,
minIdx([-1 .. 4] times TRUE) => -1 )
maxIdx(A) Maximal index of array
( Type of result: integer,
maxIdx(3 times TRUE) => 3 )
rand(A) Random element from an array
The random elements are uniform distributed.
( Type of result: baseType )
remove(A,B) Remove element with index B from array A and
return the removed element
( Type of argument B: integer,
Type of result: baseType,
remove(0 times TRUE, 1) => EXCEPTION RANGE_ERROR )
sort(A) Sort array using the compare(baseType, baseType) function
Statements:
A &:= B Append B to A
( A &:= B => A := A & B )
for A range B do
C
end for Loop over all elements of an array
( Type of argument A: baseType,
Type of argument C: proc )
insert(A, B, C) Insert C to the array A at position B
( Type of argument B: integer,
Type of argument C: baseType )
insert(A, B) Insert B into the sorted array A
( Type of argument C: baseType )
5.11 hash
The type 'hash [keyType] baseType' describes hash tables with elements of 'baseType' which can be accessed using an index of 'keyType'. For example: 'hash [string] integer' describes hash table of integer elements with a 'string' key.
Constants:
hashType.EMPTY_HASH Empty hashtable
Infix operators:
in Element
( Left argument: baseType,
Type of result: boolean )
not in Is not Element
( Left argument: baseType,
Type of result: boolean )
Indices:
[ A ] Access one hashtable element
( Type of argument A: keyType,
Type of result: baseType )
Functions:
length(A) Number of elements in hashtable A
( Type of result: integer,
length(hashType.EMPTY_HASH) => 0 )
keys(A) Unsorted array of keys of the hashtable A
( Type of result: array keyType )
values(A) Unsorted array of valuess of the hashtable A
( Type of result: array baseType )
flip(A) Deliver a hash with keys and values flipped
( Type of result: hash [baseType] array keyType )
Statements:
incl(A,B,C) Include element B to hashtable A
( Type of argument B: keyType,
Type of argument C: baseType )
excl(A,B) Exclude element B from hashtable A
( Type of argument B: keyType )
A @:= [B] C Assign C to element B of hashtable A
( Type of argument B: keyType,
Type of argument C: baseType )
for A range B do
C
end for Unsorted loop over all values of a hash
( Type of argument A: baseType,
Type of argument C: proc )
for key A range B do
C
end for Unsorted loop over all keys of a hash
( Type of argument A: keyType,
Type of argument C: proc )
for A key B range C do
D
end for Unsorted loop over all values and keys of a hash
( Type of argument A: baseType,
Type of argument B: keyType,
Type of argument D: proc )
5.12 set
The type 'set of baseType' describes a set of elements of a 'baseType'. (including the empty set).
Constants:
setType.EMPTY_SET Empty set
Infix operators:
| Union
& Intersection
- Difference
>< Symmetric Difference
in Element
( Left argument: baseType,
Type of result: boolean )
not in Is not Element
( Left argument: baseType,
Type of result: boolean )
Relations:
=, <>, <, <=, >, >=
Functions:
card Cardinality of a set
( Type of result: integer,
card(setType.EMPTY_SET) = 0 )
min Minimal element
( Type of result: baseType,
Delivers the element from the set for
which the following condition holds:
Element <= X
for all X which are in the set.
min(setType.EMPTY_SET) => EXCEPTION RANGE_ERROR )
max Maximum element
( Type of result: baseType,
Delivers the element from the set for
which the following condition holds:
Element >= X
for all X which are in the set.
min(setType.EMPTY_SET) => EXCEPTION RANGE_ERROR )
compare(A, B) Compare function
( Type of result: integer )
hashCode(A) Hash function
( Type of result: integer )
Statements:
incl(A,B) Include element B to set A
( Type of argument B: baseType )
excl(A,B) Exclude element B from set A
( Type of argument B: baseType )
for A range B do
C
end for Loop over all elements of a set
( Type of argument A: baseType,
Type of argument C: proc )
5.13 struct
The type 'struct' describes all structured types.
Type generators:
new struct
var aType: name is value;
...
end struct
Create new structure type
new metaType struct
var aType: name is value;
...
end struct
Create new structure type as subtype of 'metaType',
which is not a structure
sub metaType struct
var aType: name is value;
...
end struct
Create new structure type as subtype of 'metaType',
which is a structure type. The new stucture type inherits all
elements of the structure type 'metaType'.
var aType: name is value
Declare structure element 'name' with 'value'
Infixoperators:
. Access Element of STRUCT
( example.element )
-> Access Element of ptr STRUCT
( example->element )
Relations:
=, <>
Funktions:
incl(A, B) Include element in MODULE
( Type of argument B: reference )
excl(A, B) Exclude element from MODULE
( Type of argument B: reference )
5.14 category
The type 'category' describes the category of a 'reference'.
Constants:
SYMBOLOBJECT, DECLAREDOBJECT, FORWARDOBJECT, FWDREFOBJECT, BLOCKOBJECT,
CALLOBJECT,MATCHOBJECT, TYPEOBJECT, FORMPARAMOBJECT, INTOBJECT,
BIGINTOBJECT, CHAROBJECT, STRIOBJECT, BSTRIOBJECT, ARRAYOBJECT,
HASHOBJECT, STRUCTOBJECT, CLASSOBJECT, INTERFACEOBJECT, SETOBJECT,
FILEOBJECT, SOCKETOBJECT, LISTOBJECT, FLOATOBJECT, WINOBJECT,
ENUMLITERALOBJECT, CONSTENUMOBJECT, VARENUMOBJECT, REFOBJECT,
REFLISTOBJECT, EXPROBJECT, ACTOBJECT, VALUEPARAMOBJECT, REFPARAMOBJECT,
RESULTOBJECT, LOCALVOBJECT, PROGOBJECT
Infix operators:
category conv A Conversion to category
( Type of argument A: integer,
category conv ord(INTOBJECT) => INTOBJECT )
category parse A Conversion of string to category
( Type of argument A: string,
category parse "FLOATOBJECT" => FLOATOBJECT )
Relations:
=, <>
Functions:
ord(A) Ordinal number
( Type of result: integer )
str(A) Conversion to string
( Type of result: string,
str(CHAROBJECT) => "CHAROBJECT" )
5.15 reference
The type 'reference' describes a reference to any object.
Constants:
NIL Reference to no element.
Relations:
=, <>
Functions:
category(A) Get the category of the referenced object
( Type of result: category )
str(A) Conversion to string
( Type of result: string )
getType(A) Get the type of the referenced object
( Type of result: type )
obj_number(A) Delivers an unique number for each object
( Type of result: integer )
is_var(A) Reference to a variable object
( Type of result: boolean )
params(A) Gets the formal params of a function
( Type of result: ref_list )
local_vars(A) Gets the local variables of a function
( Type of result: ref_list )
local_consts(A) Gets the local constants of a function
( Type of result: ref_list )
body(A) Gets the body of a function
func_result(A) Gets the result object of a function
func_res_init(A) Gets the init value of the result
object of a function
array_to_list(A) Return the array elements as list
( Type of result: ref_list )
array_min_index(A) Return the minimal index of an array
( Type of result: integer )
array_max_index(A) Return the maximal index of an array
( Type of result: integer )
struct_to_list(A) Return the struct elements as list
( Type of result: ref_list )
interface_to_struct(A) Return the struct to which the interface object points.
file(A) File name of the referenced object
( Type of result: string )
line(A) Line number of the referenced object
( Type of result: integer )
alloc(A) Create a copy of the object referenced by A
The object value of the copy is set to NULL
getValue(A, reference) Dereference as reference
( Type of result: reference )
getValue(A, ref_list) Dereference as ref_list
( Type of result: ref_list )
getValue(A, integer) Dereference as integer
( Type of result: integer )
getValue(A, bigInteger) Dereference as bigInteger
( Type of result: bigInteger )
getValue(A, float) Dereference as float
( Type of result: float )
getValue(A, char) Dereference as char
( Type of result: char )
getValue(A, string) Dereference as string
( Type of result: string )
getValue(A, bitset) Dereference as bitset
( Type of result: bitset )
getValue(A, PRIMITIVE_FILE) Dereference as PRIMITIVE_FILE
( Type of result: PRIMITIVE_FILE )
getValue(A, program) Dereference as program
( Type of result: program )
getValue(A, ACTION) Dereference as ACTION
( Type of result: ACTION )
getValue(A, type) Dereference as type
( Type of result: type )
compare(A, B) Compare function
( Type of result: integer )
hashCode(A) Hash function
( Type of result: integer )
Statements:
setCategory(A, B) Set the category of the referenced object A to B
( Type of argument B: category )
setType(A, B) Set the type of the referenced object A to B
( Type of argument B: type )
setValue(A, B) Set the value of the referenced object A to B
( Type of argument B: ref_list )
setParams(A, B) Set the formal params of a function
( Type of argument B: ref_list )
5.16 ref_list
The type 'ref_list' describes a list of 'reference' objects.
Constants:
ref_list.EMPTY Empty reference list.
Infix operators:
& Ref_list list concatenation
A in B Is element in ref_list
( Type of argument A: reference,
Type of result: boolean )
A not in B Is element not in ref_list
( Type of argument A: reference,
Type of result: boolean )
Indices:
[ A ] Access one ref_list element
( Type of argument A: integer,
Type of result: reference,
A[1]=>First element,
A[length(A)]=>Last element,
A[0] => EXCEPTION RANGE_ERROR,
A[succ(length(A))] => EXCEPTION RANGE_ERROR )
[ A .. B ] Access a sub list
( Type of arguments A and B: integer )
[ A .. ] Access a sub list beginning at position A
( Type of argument A: integer )
[ .. A ] Access a sub list ending at position A
( Type of argument A: integer )
Relations:
=, <>
Funktions:
length(A) Length of ref_list
( Type of result: integer,
length(ref_list.EMPTY) => 0 )
make_list(A) Create ref_list with element A
( Type of argument A: reference )
pos(A,B) First position of reference B in ref_list A
( Type of argument B: reference,
Type of result: integer )
pos(A,B,C) First position of reference B in ref_list A
The search starts at position C of ref_list A
( Type of argument B: reference,
Type of argument C: integer,
Type of result: integer )
incl(A, B) Include element in list
( Type of argument B: reference )
excl(A, B) Exclude element from list
( Type of argument B: reference )
Statements:
A &:= B Append B to A
( A &:= B => A := A & B )
A @:= [B] C Assign C to element B of ref_list A
( Type of argument B: integer,
Type of argument C: reference )
for A range B do
C
end for Loop over all elements of a ref_list
( Type of argument A: reference,
Type of argument C: proc )
5.17 program
The type 'program' describes a Seed7 program.
Constants:
program.EMPTY Empty program.
Relations:
=, <>
Funktions:
parseFile(A) Parse the file with the name A
( Type of argument A: string )
parseStri(A) Parse the string A
( Type of argument A: string )
evaluate(A, B) Evaluate the expression B which is part of program A
( Type of result: reference,
Type of argument A: program,
Type of argument B: reference )
sys_var(A, B) Return a reference of the system var B of program A
( Type of result: reference,
Type of argument A: program,
Type of argument B: string )
error_count(A) Number of errors in the program A
( Type of result: integer,
Type of argument A: program )
declared_objects(A) List of objects declared in the program A
( Type of result: ref_list,
Type of argument A: program )
Statements:
execute(A) Execute the program referred by A
5.18 ptr
The type 'ptr baseType' describes a pointer to an object of a 'baseType'. With
const type: ptrType is ptr baseType;
a new pointer type 'ptrType' is declared.
Constants:
ptrType.NIL Reference to no element
Prefix operators:
& Address of
( Type of operand: baseType )
Postfix operators:
^ Dereference
( Type of result: baseType )
Infix operators:
ptrType conv A Conversion from reference A to ptrType
reference conv A Conversion from ptrType A to reference
Relations:
=, <>
Functions:
base_type(ptrType) Gets the baseType of a ptrType
( Type of argument ptrType: type )
5.19 ENUMERATION
With
const type: enumType is new enum
enum_literal1, enum_literal2
end enum;
a new enumeration type is declared. The values of this type are:
enum_literal1 and enum_literal2
For a enumeration type only few operations are predefined. Additional operations must be defined separately. So it is necessary to define the 'str' and 'parse' functions in order to do i/o for a new enumeration type.
Infix operators:
enumType conv A Conversion from integer A to enumType
( Type of argument A: integer,
enumType conv 0 => enum_literal1 )
integer conv A Conversion from enumType A to integer
( Type of result: integer,
integer conv enum_literal1 => 0 )
Relations:
=, <>, <, <=, >, >=
Funktions:
ord(A) Ordinal number
( Type of result: integer )
succ(A) Successor
( succ(A)=>enumType conv(succ(ord(A))) )
pred(A) Predecessor
( pred(A)=>enumType conv(pred(ord(A))) )
Statements:
incr(A) Increment
( incr(A) => A:=succ(A) )
decr(A) Decrement
( decr(A) => A:=pred(A) )
5.20 color
The type 'color' describes colors.
Constants:
black is color(0, 0, 0);
dark_red is color(32768, 0, 0);
dark_green is color(0, 32768, 0);
brown is color(32768, 16384, 0);
dark_blue is color(0, 0, 32768);
dark_magenta is color(32768, 0, 32768);
dark_cyan is color(0, 65535, 65535);
light_gray is color(49152, 49152, 49152);
dark_gray is color(16384, 16384, 16384);
light_red is color(65535, 0, 0);
light_green is color(0, 65535, 0);
yellow is color(65535, 65535, 0);
light_blue is color(0, 0, 65535);
light_magenta is color(65535, 0, 65535);
light_cyan is color(32768, 65535, 65535);
white is color(65535, 65535, 65535);
orange is color(65535, 32768, 0);
amber is color(49152, 32768, 16384);
pink is color(65535, 32768, 32768);
Infix operators:
+ Add two colors in an additive color system
Relations:
=, <>
Functions:
color(R,G,B) Creates a color from Red, Green and Blue
( Type of argument R: integer,
Type of argument G: integer,
Type of argument B: integer )
5.21 time
The type 'time' describes times and dates.
Infix operators:
+ Add a duration to a time
( Type of right operand: duration )
- Subtract a duration from a time
( Type of right operand: duration )
- Subtract two times
( Type of result: duration )
time parse A Conversion of string to time
( Type of argument A: string,
time parse "2005-02-28 12:00:01" => 2005-02-28 12:00:01,
time parse "2005-02-29 12:00:01" => EXCEPTION RANGE_ERROR )
Relations:
=, <>, <, <=, >, >=
Functions:
time(NOW) Gets the current time
str(A) Conversion to string
( Type of result: string )
str_date(A) Conversion of the date to string
( Type of result: string )
str_time(A) Conversion of the daytime to string
( Type of result: string )
truncToSecond(A) Trunc a time to a second
truncToMinute(A) Trunc a time to a minute
truncToHour(A) Trunc a time to a hour
truncToDay(A) Trunc a time to a day
truncToMonth(A) Trunc a time to a month
truncToYear(A) Trunc a time to a year
isLeapYear(A) Determine if a given year is a leap year
( Type of argument A: integer )
( Type of result: boolean )
daysInMonth(Y, M) Calculate the number of days in a month
( Type of argument Y: integer,
Type of argument M: integer,
Type of result: integer )
dayOfWeek(A) Day of the week with Monday as 1
( Type of result: integer )
dayOfYear(A) Day of the year with 1 January as 1
( Type of result: integer )
weekOfYear(A) Compute the week number of a year (0 to 53).
According to ISO 8601: Week number 1 of
every year contains the 4. of january.
( Type of result: integer )
weekDateYear(A) Compute the year of the ISO 8601 week date
( Type of result: integer )
weekDateWeek(A) Compute the week of the ISO 8601 week date
( Type of result: integer )
toGMT(A) Conversion to Greenwich Mean Time
julianDayNumber(A) Number of days that have elapsed since
January 1, 4713 BC in the proleptic Julian calendar
( Type of result: integer )
julianDayNumToTime(A) Convert julian day number to time
( Type of argument A: integer )
compare(A, B) Compare function
( Type of result: integer )
hashCode(A) Hash function
( Type of result: integer )
Statements:
A +:= B Increment A by B
( Type of argument B: duration,
A +:= B => A := A + B )
A -:= B Decrement A by B
( Type of argument B: duration,
A -:= B => A := A - B )
await(A) Wait until the given time
5.22 duration
The type 'duration' describes time and date durations.
Prefix operators:
+ Identity
- Change sign
Infix operators:
+ Add two durations
- Subtract two durations
* Multiply a duration by an integer
( Type of left operand: integer )
* Multiply a duration by an integer
( Type of right operand: integer )
duration parse A Conversion of string to duration
( Type of argument A: string,
duration parse "0-02-28 12:00:01" => 0-02-28 12:00:01,
duration parse "0-13-29 12:00:01" => EXCEPTION RANGE_ERROR )
Relations:
=, <>, <, <=, >, >=
Functions:
years(A) Years of the duration
( Type of result: integer )
months(A) Months of the duration
( Type of result: integer )
days(A) Days of the duration
( Type of result: integer )
hours(A) Hours of the duration
( Type of result: integer )
minutes(A) Minutes of the duration
( Type of result: integer )
seconds(A) Seconds of the duration
( Type of result: integer )
mycro_seconds(A) Mycro seconds of the duration
( Type of result: integer )
str(A) Conversion to string
( Type of result: string )
compare(A, B) Compare function
( Type of result: integer )
hashCode(A) Hash function
( Type of result: integer )
Statements:
wait(A) Wait for given duration
5.23 file
The type 'file' describes sequential files.
Constants:
STD_NULL Standard null file
STD_IN Standard input of the operating system
STD_OUT Standard output of the operating system
STD_ERR Standard error output of the operating system
Variables:
IN Standard input file used for file input
operations when no file is specified
( IN is initialized with STD_IN )
OUT Standard output file used for file output
operations when no file is specified
( OUT is initialized with STD_OUT )
Relations:
=, <>
Functions:
open(A, B) Open external file
( Type of argument A: string,
Type of argument B: string,
Type of result: file,
Returns STD_NULL if open was not
possible )
open_utf8(A, B) Open external UTF-8 file
( Type of argument A: string,
Type of argument B: string,
Type of result: file,
Returns STD_NULL if open was not
possible )
popen(A, B) Open a pipe to a process
( Type of argument A: string,
Type of argument B: string,
Type of result: file,
Returns STD_NULL if popen was not
possible )
openInetSocket(port) Open local internet client socket
( Type of argument port: integer,
Type of result: file,
Returns STD_NULL if open was not
possible )
openInetSocket(addr, port) Open internet client socket
( Type of argument addr: string,
Type of argument port: integer,
Type of result: file,
Returns STD_NULL if open was not
possible )
length(A) Length of file A
( Type of result: integer )
tell(A) Return the actual file position
( Type of argument: file,
The first position in the file is 1 )
getc(A) Get one character from file A
( Type of result: char )
gets(A, B) Get string with maximum length B from file A
( Type of argument A: integer,
Type of argument B: file,
Type of result: string,
gets(A, -1) => EXCEPTION RANGE_ERROR )
getwd(A) Get one word from file A
( Type of result: string )
getln(A) Get one line from file A
( Type of result: string )
eoln(A) End of line
( Type of result: boolean )
hasNext(A) A call of getc does not return the EOF character
( Type of result: boolean )
eof(A) End of file
( Type of result: boolean )
Statements:
write(A, B) Write string B to file A
( Type of argument B: string )
writeln(A) Write a new line to file A
writeln(A, B) Write string B and new line to file A
( Type of argument B: string )
read(A, B) Read a word from file A into string B
( Type of right operand: string )
readln(A) Read a line from file A
readln(A, B) Read a line from file A into the string B
( Type of right operand: string )
backSpace(A) Write backspace to file A
close(A) Close file A
flush(A) Flush file A
seek(A, B) Set actual file position of file A to B
( Type of argument B: integer,
seek(A, 1) => Set to file begin,
seek(A, length(A)) => Set to last position,
seek(A, length(A) + 1) => Set to end of file,
seek(A, -1) => EXCEPTION RANGE_ERROR )
5.24 text
The type 'text' describes two dimensional files.
Relations:
=, <>
Functions:
open_window(F, A, B, C, D) Open a text
( Type of argument A: integer,
Type of argument B: integer,
Type of argument C: integer,
Type of argument D: integer )
height(A) Height of the text
( Type of result: integer )
width(A) Width of the text
( Type of result: integer )
line(A) Current line of the text
( Type of result: integer )
column(A) Current column of the text
( Type of result: integer )
Statements:
write(A, B) Write string B to text A
( Type of argument B: string )
writeln(A) Write a new line to text A
writeln(A, B) Write string B and new line to text A
( Type of argument B: string )
read(A, B) Read a word from text A into string B
( Type of right operand: string )
readln(A) Read a line from text A
readln(A, B) Read a line from text A into the string B
( Type of right operand: string )
backSpace(A) Write backspace to text A
close(A) Close text A
flush(A) Flush text A
clear(A) Clear the window
v_scroll(A) Scroll the window vertical
h_scroll(A) Scroll the window horizontal
color(A, B) Set foreground color of the text A
( Type of argument B: color )
color(A, B, C) Set foreground and background color of the text A
( Type of argument B: color,
Type of argument C: color )
setPos(A, B, C) Set the current position of the text A
( Type of argument B: integer
Type of argument C: integer )
setLine(A, B) Set the current line of the text A
( Type of argument B: integer )
setColumn(A, B) Set the current column of the text A
( Type of argument B: integer )
box(A) Write a box around the window
clear_box(A) Clear the box around the window
cursor_on(A) Make the cursor visible
cursor_off(A) Make the cursor invisible
5.25 func
The type 'func baseType' describes functions which return a 'baseType'. For example: 'func integer' describes an 'integer' function.
Values:
ord, str, abs, sqrt, rand, A + B, A * B, A ** B,
trunc, round, sin, cos, compare, hashCode, pos,
replace, trim, length, keys, color, dayOfWeek,
...
Every function declared with const func ... is a value
Prefix operators:
func
result
var baseType: result is baseType.value;
begin
statements
end func
Create a baseType function
( Type of 'statements': proc,
Type of result: func baseType )
func
result
var baseType: result is baseType.value;
local
declarations
begin
statements
end func
Create a baseType function with local variables
( Type of 'declarations': proc,
Type of 'statements': proc,
Type of result: func baseType )
return value
Create a function with the result type of value
( Type of value: anyType - which means: any type,
Type of result: func anyType )
Functions are declared as constants with a 'func' type and are initialized with a 'func result ...' or 'return ...' operator. For example:
const func integer: tak (in integer: x, in integer: y, in integer: z) is func
result
var integer: result is 0;
begin
if y >= x then
result := z;
else
result := tak(tak(pred(x), y, z),
tak(pred(y), z, x),
tak(pred(z), x, y));
end if;
end func
Another example using the 'return' function:
const func float: convertRadianToDegree (in float: x) is
return x * 57.295779513082320876798154814114;
This 'return' function should not be confused with a 'return' statement. It is important to note that no 'return' statement exists. The declaration for the 'return' function is as follows:
const func func aType: return (ref func aType param) is action "PRC_RETURN";
const func func aType: return (ref aType param) is action "PRC_RETURN";
The 'func' types can also be used for parameters. Functions which use a 'func' parameter do not evaluate this parameter before the function call. Instead this parameter can be evaluated zero or more times inside the function. For example:
const func boolean: (in boolean: first) and (in func boolean: second) is func
result
var boolean: result is FALSE;
begin
if first then
result := second;
end if;
end func;
Here the second parameter is only evaluated when the first parameter is 'TRUE'. 5.26 varfuncThe type 'varfunc baseType' describes functions which return a 'baseType' variable. For example: A function which returns an 'integer' variable is described with 'varfunc integer'. A call of a 'varfunc' can be used at the left side of an assignment. Generally a 'varfunc' can be used at places where an 'inout' parameter requests a variable.
Prefix operators:
return var value;
Create a varfunc which returns the variable 'value'
( Type of value: anyType - which means: any type,
Accessright of value: var = A variable, an 'inout' parameter or a 'varfunc'
Type of result: varfunc anyType )
Varfunctions are used to express 'array', 'hash' and 'struct' accesses which can be used at the left and right side of an assignment. The access function for a 'hash' is defined as:
const func baseType: (in hashType: aHash) [ (in keyType: aKey) ] is
return INDEX(aHash, aKey, hashCode(aKey), hashType.keyCompare);
const varfunc baseType: (inout hashType: aHash) [ (in keyType: aKey) ] is
return var INDEX(aHash, aKey, hashCode(aKey), hashType.keyCompare);
The example above shows that functions with 'in' and 'inout' parameters can be overloaded. At the right side of an assignment the 'func' is called, while at the left side the 'varfunc' is called. That way the access functions of arrays, hashs and structs can be used in the usual way. 5.27 voidThe type 'void' describes the empty type.
Value:
empty This is the only value of the type 'void'.
5.28 proc
The type 'proc' describes procedures. The type 'proc' is defined as 'func void'.
Values:
noop;
while ... do ... end while;
repeat ... until ... ;
writeln( ... );
A := B;
incr(A);
...
Every procedure declared with const proc: ... is a value
The procedure 'noop' does nothing and is used as empty procedure.
Prefix operators:
func
begin
statements
end func
Create a procedure
( Type of 'statements': proc,
Type of result: proc )
func
local
declarations
begin
statements
end func
Create a procedure with local variables
( Type of 'declarations': proc,
Type of 'statements': proc,
Type of result: proc )
5.29 type
The type 'type' describes all types.
Values:
void, boolean, integer, rational, float, char,
string, reference, ref_list, color, time, duration
file, proc, type, ...
Every type declared with const type: ... is a value
The type 'void' is used as empty type.
Prefix operators:
func Function type
( func char => Function which returns a char )
varfunc Varfunc type
( varfunc char => Function which returns a char variable )
ptr Pointer type
( ptr bitset => Pointer to bitset )
array Array type
( array string => Array of strings )
set of Set type
( set of integer => Set of integer )
subtype Create subtype of existing type
( subtype char => Subtype of char )
Relations:
=, <>
Functions |