Seed7 - The extensible programming language
Seed7 FAQ Manual Screenshots Examples Libraries Algorithms Download Links
Manual Introduction Tutorial Declarations Statements Types Parameters Objects File System Syntax Tokens Expressions OS access Actions Foreign funcs Errors
Types boolean integer bigInteger rational bigRational float complex char string array hash set struct category reference ref_list program ptr enumeration color time duration file text func varfunc void proc type object expr
Manual
Types
 previous   up   next 

5. PREDEFINED TYPES

In the following sub-chapters the predefined types of the standard library are introduced. The operators have, when not stated otherwise, the type described in the sub-chapter as parameter type and result type. The relations have also the type described in the sub-chapter as parameter type and a result of type boolean. In the descriptions is used to show an equivalent expression.

5.1 boolean

The type boolean consists of the two truth values TRUE and FALSE. The boolean functions are defined in the library "boolean.s7i".

    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 of integer 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 )
      compare(A, B) Compare function
                  ( Type of result: integer,
                    compare(FALSE, TRUE)  -1,
                    compare(TRUE, TRUE)  0,
                    compare(TRUE, FALSE)  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) )

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 behavior of different boolean expressions:

Expression Result when the first operand evaluates to
FALSE 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 64-bit integer numbers. An integer 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

When an integer operation overflows it raises the exception OVERFLOW_ERROR. The integer functions are defined in the library "integer.s7i".

    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 for every A, even for A = 0,
                    1 ** B  1 for B >= 0,
                    A ** B  -(-A) ** B for A <= 0 and B >= 0 and odd(B),
                    A ** B  (-A) ** B for A <= 0 and B >= 0 and not odd(B),
                    A ** -1  EXCEPTION NUMERIC_ERROR )
      A << B    Shift left
                  ( A << B is okay for B >= 0 and B <= 63,
                    A << B  EXCEPTION OVERFLOW_ERROR for B < 0 or B >= 64,
                    A << B  A * 2 ** B,
                    A << 0  A )
      A >> B    Arithmetic shift right
                  ( A >> B is okay for B >= 0 and B <= 63,
                    A >> B  EXCEPTION OVERFLOW_ERROR for B < 0 or B >= 64,
                    A >> B  A mdiv 2 ** B  for B <= 62,
                    A >> 0  A,
                    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)),
                    0 >> B  0 )
      !         Binomial coefficient
                  ( n ! k  !n div (!k * !(n - k)) )
      A radix B  Convert the integer A to a string. The conversion
                 uses the numeral system with the base B.
                  ( Type of result: string,
                    48879 radix 16  "beef",
                    -48879 radix 16  "-beef",
                    123 radix 37  EXCEPTION RANGE_ERROR )
      A RADIX B  Convert the integer A to a string. The conversion
                 uses the numeral system with the base B.
                  ( Type of result: string,
                    48879 RADIX 16  "BEEF",
                    -48879 RADIX 16  "-BEEF",
                    123 RADIX 37  EXCEPTION RANGE_ERROR )
      lpad      Left padding with spaces
                  ( 123 lpad  8  "     123",
                    123 lpad  4  " 123",
                    123 lpad  3  "123",
                    123 lpad  2  "123",
                    123 lpad -8  "123" )
                    -12 lpad  4  " -12",
                    -12 lpad  3  "-12",
                    -12 lpad  2  "-12" )
      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" )
      rpad      Right padding with spaces
                  ( 123 rpad  8  "123     ",
                    123 rpad  4  "123 ",
                    123 rpad  3  "123",
                    123 rpad  2  "123",
                    123 rpad -8  "123" )
                    -12 rpad  4  "-12 ",
                    -12 rpad  3  "-12",
                    -12 rpad  2  "-12" )
      sci       Conversion to a string in scientific notation
                  ( Type of result: string,
                    12345 sci 4  "1.2345e+4",
                    12345 sci 3  "1.235e+4",
                    12345 sci 2  "1.23e+4",
                    3141592 sci 0  "3e+6",
                    27182818 sci 0  "3e+7",
                    2**62 sci 6  "4.611686e+18",
                    -1 sci 3  "-1.000e+0",
                    -0 sci 2  "0.00e+0" )
      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,
                    str(12345)  "12345" )
      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 )
      log10(A)  Truncated base 10 logarithm
                  ( log10(A) is defined for A >= 0
                    log10(10 ** A) = A for A >= 0,
                    log10(pred(10 ** A)) = pred(A) for A >= 0,
                    log10(10)  1,
                    log10(1)  0,
                    log10(0)  -1,
                    log10(-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(pred(2 ** A)) = pred(A) for A >= 0,
                    log2(2)  1,
                    log2(1)  0,
                    log2(0)  -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)  bitLength(pred(-A)) for A < 0,
                    bitLength(0)  0,
                    bitLength(-1)  0 )
      lowestSetBit(A) Index of the lowest-order one bit
                      For A <> 0 this is equal to the 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 )
      min(A, B) Minimum of two numbers.
                  ( min(1, 2)  1 )
      max(A, B) Maximum of two numbers.
                  ( max(1, 2)  2 )
      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.
    A mdiv 2 ** B = A >> B            when 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.

Tables for the behavior 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. A bigInteger literal is a sequence of digits followed by an underscore character (for example 1_ ). 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. Like decimal bigInteger literals the extended digits must be followed by an underscore character. Examples of bigInteger literals are:

    0_   18446744073709551616_ 16#deadbeefcafe_

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. The bigInteger functions are defined in the library "bigint.s7i".

    Prefix operators:
      +         Identity
      -         Change sign
      !         Factorial
    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_ for every A, even for A = 0_,
                    1_ ** B  1_ for B >= 0,
                    A ** B  -(-A) ** B for A <= 0 and B >= 0 and odd(B),
                    A ** B  (-A) ** B for A <= 0 and B >= 0 and not odd(B),
                    A ** -1  EXCEPTION NUMERIC_ERROR )
      A << B    Shift left
                  ( Type of argument B: integer,
                    A << B  A * 2_ ** B  for B >= 0,
                    A << B  A >> -B for B < 0,
                    A << 0  A,
                    0_ << B  0_ for every B )
      A >> B    Arithmetic shift right
                  ( Type of argument B: integer,
                    A >> B  A mdiv 2_ ** B for B >= 0,
                    A >> B  A << -B for B < 0,
                    A >> 0  A,
                    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)),
                    0_ >> B  0_ for every B )
      A radix B  Convert the bigInteger A to a string. The conversion
                 uses the numeral system with the base B.
                  ( Type of result: string,
                    3735928559_ radix 16  "deadbeef",
                    -3735928559_ radix 16 )  "-deadbeef",
                    123_ radix 37  EXCEPTION RANGE_ERROR )
      A RADIX B  Convert the integer A to a string. The conversion
                 uses the numeral system with the base B.
                  ( Type of result: string,
                    3735928559_ RADIX 16  "DEADBEEF",
                    -3735928559_ RADIX 16 )  "-DEADBEEF",
                    123_ RADIX 37  EXCEPTION RANGE_ERROR )
      sci       Conversion to a string in scientific notation
                  ( Type of right operand: integer,
                    Type of result: string,
                    12345_ sci 4  "1.2345e+4",
                    12345_ sci 3  "1.235e+4",
                    12345_ sci 2  "1.23e+4",
                    3141592_ sci 0  "3e+6",
                    27182818_ sci 0  "3e+7",
                    2_**62 sci 6  "4.611686e+18",
                    -1_ sci 3  "-1.000e+0",
                    -0_ sci 2  "0.00e+0" )
      bigInteger conv A   Conversion of integer to bigInteger
                  ( Type of argument A: integer,
                    bigInteger conv 1  1_ )
      bigInteger parse A   Conversion of string to integer
                  ( Type of argument A: string,
                    bigInteger parse "123"  123_,
                    bigInteger parse "-123"  -123_,
                    bigInteger parse "+5"  5_,
                    bigInteger parse " 1"  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,
                    str(9876543210_)  "9876543210" )
      sqrt(A)   Integer square root
                  ( sqrt(A) is okay for A >= 0_
                    sqrt(A)  trunc(sqrt(flt(A))),
                    sqrt(-1_)  EXCEPTION NUMERIC_ERROR )
      modInverse(A, B) Compute the modular multiplicative inverse of A modulo B
      log10(A)  Truncated base 10 logarithm
                  ( log10(A) is defined for A >= 0_
                    log10(10_ ** A) = A for A >= 0_,
                    log10(pred(10_ ** A)) = pred(A) for A >= 0_,
                    log10(10_)  1_,
                    log10(1_)  0_,
                    log10(0_)  -1_,
                    log10(-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(pred(2_ ** A)) = pred(A) for A >= 0,
                    log2(2_)  1_,
                    log2(1_)  0_,
                    log2(0_)  -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)  bitLength(pred(-A)) for A < 0_,
                    bitLength(0_)  0,
                    bitLength(-1_)  0 )
      lowestSetBit(A) Index of the lowest-order one bit
                      For A <> 0_ this is equal to the 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 )
      min(A, B) Minimum of two numbers.
                  ( min(1_, 2_)  1_ )
      max(A, B) Maximum of two numbers.
                  ( max(1_, 2_)  2_ )
      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.
    A mdiv 2_ ** B = A >> B           when 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.

Tables for the behavior 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. When a rational operation overflows it raises the exception OVERFLOW_ERROR. In integer computations an overflow can only happen with very huge positive or negative numbers. In rational computations an overflow can happen with small numbers. Because of widening big denominators can be produced easily. E.g.: 1/1777 + 1/1999 = 3776/3552223 . The rational functions are defined in the library "rational.s7i".

    Elements:
      var integer: numerator is 0;
      var integer: denominator is 1;
    Prefix operators:
      +         Identity
      -         Change sign
    Infix operators:
      +         Addition
      -         Subtraction
      *         Multiplication
      /         Division
      /         Create rational from numerator and denominator
                  ( Type of left operand: integer,
                    Type of right operand: integer )
      **        Power
                  ( rational ** integer )
      rational conv A   Conversion of integer to rational
                  ( Type of argument A: integer,
                    rational conv 1  1 / 1 )
      digits    Conversion to string with specified precision
                  ( Type of right operand: integer,
                    Type of result: string,
                    1/64 digits 7  "0.0156250",
                    1/64 digits 4  "0.0156",
                    1/64 digits 2  "0.02",
                    355/113 digits 6  "3.141593",
                    22/7 digits 0  "3",
                    -1/2 digits 1  "-1",
                    1/0 digits 5  "Infinity",
                    -1/0 digits 6  "-Infinity",
                    0/0 digits 7  "NaN",
                    -1/2048 digits 3  "0.000" )
      sci       Conversion to a string in scientific notation
                  ( Type of right operand: integer,
                    Type of result: string,
                    1/64 sci 4  "1.5625e-2",
                    1/64 sci 3  "1.563e-2",
                    1/64 sci 2  "1.56e-2",
                    355/113 sci 6  "3.141593e+0",
                    22/7 sci 0  "3e+0",
                    -1/2 sci 1  "-5.0e-1",
                    1/0 sci 5  "Infinity",
                    -1/0 sci 6  "-Infinity",
                    0/0 sci 7  "NaN",
                    -1/2048 sci 3  "-4.883e-4",
                    -0/1 sci 2  "0.00e+0" )
      rational parse A   Conversion of string to rational
                  ( Type of argument A: string )
    Relations:
      =, <>, <, <=, >, >=
    Functions:
      abs(A)    Absolute value
      rat(A)    Conversion of integer to rational
                  ( Type of argument A: integer,
                    rat(1)  1 / 1 )
      floor(A)  Truncation towards negative infinity
                  ( Type of result: integer,
                    floor(9/5)   1, floor(1/1)   1,
                    floor(-1/1)  -1, floor(-9/5)  -2 )
      ceil(A)   Rounding up towards positive infinity
                  ( Type of result: integer,
                    ceil(6/5)   2, ceil(1/1)   1,
                    ceil(-1/1)  -1, ceil(-6/5)  -1 )
      trunc(A)  Truncation towards zero
                  ( Type of result: integer,
                    trunc(9/5)   1, trunc(1/1)   1,
                    trunc(-1/1)  -1, trunc(-9/5)  -1 )
      round(A)  Round towards zero
                  ( Type of result: integer,
                    round(1/2)  1, round(-1/2)  -1,
                    round(2/5)  0, round(-2/5)  0 )
      str(A)    Conversion to string
                  ( Type of result: string )
      min(A, B) Minimum of two numbers.
                  ( min(2/5, 1/2)  2/5 )
      max(A, B) Maximum of two numbers.
                  ( max(2/5, 1/2)  1/2 )
      compare(A, B) Compare function
                  ( Type of result: integer,
                    compare(19/10, 2/1)  -1,
                    compare(26/5, 26/5)  0,
                    compare(8/1, 79/10)  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 )

All calculations with rational numbers are done exact. (Without any rounding)

5.5 bigRational

The 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. The bigRational functions are defined in the library "bigrat.s7i".

    Elements:
      var bigInteger: numerator is 0_;
      var bigInteger: denominator is 1_;
    Prefix operators:
      +         Identity
      -         Change sign
    Infix operators:
      +         Addition
      -         Subtraction
      *         Multiplication
      /         Division
      /         Create bigRational from numerator and denominator
                  ( Type of left argument: bigInteger,
                    Type of right argument: bigInteger )
      **        Power
                  ( bigRational ** integer )
      bigRational conv A   Conversion of integer to bigRational
                  ( Type of argument A: integer,
                    bigRational conv 1  1_ / 1_ )
      bigRational conv A   Conversion of bigInteger to bigRational
                  ( Type of argument A: bigInteger,
                    bigRational conv 1_  1_ / 1_ )
      digits    Conversion to string with specified precision
                  ( Type of right operand: integer,
                    Type of result: string,
                    1_/64_ digits 7  "0.0156250",
                    1_/64_ digits 4  "0.0156",
                    1_/64_ digits 2  "0.02",
                    355_/113_ digits 6  "3.141593",
                    22_/7_ digits 0  "3",
                    -1_/2_ digits 1  "-1",
                    1_/0_ digits 5  "Infinity",
                    -1_/0_ digits 6  "-Infinity",
                    0_/0_ digits 7  "NaN",
                    -1_/2048_ digits 3  "0.000" )
      sci       Conversion to a string in scientific notation
                  ( Type of right operand: integer,
                    Type of result: string,
                    1_/64_ sci 4  "1.5625e-2",
                    1_/64_ sci 3  "1.563e-2",
                    1_/64_ sci 2  "1.56e-2",
                    355_/113_ sci 6  "3.141593e+0",
                    22_/7_ sci 0  "3e+0",
                    -1_/2_ sci 1  "-5.0e-1",
                    1_/0_ sci 5  "Infinity",
                    -1_/0_ sci 6  "-Infinity",
                    0_/0_ sci 7  "NaN",
                    -1_/2048_ sci 3  "-4.883e-4",
                    -0_/1_ sci 2  "0.00e+0" )
      bigRational parse A   Conversion of string to bigRational
                  ( Type of argument A: string )
    Relations:
      =, <>, <, <=, >, >=
    Functions:
      abs(A)    Absolute value
      rat(A)    Conversion of bigInteger to bigRational
                  ( Type of argument A: bigInteger,
                    rat(1_)  1_ / 1_ )
      floor(A)  Truncation towards negative infinity
                  ( Type of result: bigInteger,
                    floor(9_/5_)   1_, floor(1_/1_)   1_,
                    floor(-1_/1_)  -1_, floor(-9_/5_)  -2_ )
      ceil(A)   Rounding up towards positive infinity
                  ( Type of result: bigInteger,
                    ceil(6_/5_)   2_, ceil(1_/1_)   1_,
                    ceil(-1_/1_)  -1_, ceil(-6_/5_)  -1_ )
      trunc(A)  Truncation towards zero
                  ( Type of result: bigInteger,
                    trunc(9_/5_)   1_, trunc(1_/1_)   1_,
                    trunc(-1_/1_)  -1_, trunc(-9_/5_)  -1_ )
      round(A)  Round towards zero
                  ( Type of result: bigInteger,
                    round(1_/2_)  1_, round(-1_/2_)  -1_,
                    round(2_/5_)  0_, round(-2_/5_)  0_ )
      str(A)    Conversion to string
                  ( Type of result: string )
      min(A, B) Minimum of two numbers.
                  ( min(2_/5_, 1_/2_)  2_/5_ )
      max(A, B) Maximum of two numbers.
                  ( max(2_/5_, 1_/2_)  1_/2_ )
      compare(A, B) Compare function
                  ( Type of result: integer,
                    compare(19_/10_, 2_/1_)  -1,
                    compare(26_/5_, 26_/5_)  0,
                    compare(8_/1_, 79_/10_)  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 )

All calculations with bigRational numbers are done exact. (Without any rounding)

5.6 float

The type float consists of double precision floating point numbers. Float literals use base 10 and contain a decimal point. There must be at least one digit before and after the decimal point. An exponent part, which is introduced with E or e, is optional. The exponent can be signed, but the mantissa is not. A literal does not have a sign, + or - are unary operations. Examples of float literals are:

  3.14159265358979
  1.0E-12
  0.1234

The function str and the operators digits and parse create and accept float literals with sign. Basic float functions are defined in the library "float.s7i". Trigonometric- and other mathematical functions are defined in the library "math.s7i".

    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 is 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 )
      float conv A   Conversion of integer to float
                  ( Type of argument A: integer,
                    float conv 1  1.0 )
      digits    Conversion to string with specified precision
                  ( Type of right operand: integer,
                    Type of result: string,
                    0.012345 digits 4  "0.0123",
                    1.2468 digits 2  "1.25",
                    0.125 digits 2  "0.12",
                    0.375 digits 2  "0.38",
                    Infinity digits A  "Infinity",
                    -Infinity digits A  "-Infinity",
                    NaN digits A  "NaN" )
      sci       Conversion to a string in scientific notation
                  ( Type of right operand: integer,
                    Type of result: string,
                    0.012345 sci 4  "1.2345e-2",
                    1.2468 sci 2  "1.25e+0",
                    3.1415 sci 0  "3e+0",
                    0.125 sci 1  "1.2e-1",
                    0.375 sci 1  "3.8e-1",
                    Infinity sci 5  "Infinity",
                    -Infinity sci 6  "-Infinity",
                    NaN sci 7  "NaN",
                    -0.004 sci 2  "-4.00e-3" )
      exp       Set the number of exponent digits in a scientific float notation.
                  ( Type of left operand: string,
                    Type of right operand: integer,
                    Type of result: string,
                    0.012345 sci 4 exp 2  "1.2345e-02",
                    1.2468e15 sci 2 exp 1  "1.25e+15",
                    3.1415 sci 0 exp 3  "3e+000",
                    0.125 sci 1 exp 2  "1.2e-01",
                    0.375 sci 1 exp 2  "3.8e-01",
                    Infinity sci 5 exp 2  "Infinity",
                    -Infinity sci 6 exp 2  "-Infinity",
                    NaN sci 7 exp 2  "NaN",
                    -0.004 sci 2 exp 2  "-4.00e-03" )
      float parse A   Conversion of string to float
                  ( Type of argument A: string )
    Relations:
      =, <>, <, <=, >, >=
    Functions:
      abs(A)    Absolute value
      flt(A)    Conversion of integer 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 )
      min(A, B) Minimum of two numbers.
                  ( min(2.5, 4.5)  2.5 )
      max(A, B) Maximum of two numbers.
                  ( max(2.5, 4.5)  4.5 )
      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. The complex functions are defined in the library "complex.s7i".

    Elements:
      var float: re is 0.0;
      var float: im is 0.0;
    Prefix operators:
      +         Identity
      -         Change sign
      conj      Complex conjugate
    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 )
      complex conv A   Conversion of integer to complex
                  ( Type of argument A: integer,
                    complex conv A  complex(flt(A)) )
      complex conv A   Conversion of float to complex
                  ( Type of argument A: float,
                    complex conv A  complex(A) )
      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" )
      compare(A, B) Compare function
                  ( Type of result: integer )
      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.8 char

The type char describes Unicode characters encoded with UTF-32. In the source file a character literal is written as UTF-8 encoded Unicode character enclosed in single quotes. In order to represent non-printable characters and certain printable characters the following escape sequences may be used.

audible alert BEL \a
backspace BS \b
escape ESC \e
formfeed FF \f
newline NL (LF) \n
carriage return CR \r
horizontal tab HT \t
vertical tab VT \v
backslash (\) \\
apostrophe (') \'
double quote (") \"
control-A \A
...
control-Z \Z

Additionally the following escape sequence can be used:

  • A backslash followed by an integer literal and a semicolon is interpreted as character with the specified ordinal number. Note that the integer literal is interpreted decimal unless it is written as based integer.

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. The char functions are defined in the library "char.s7i".

    Infix operators:
      char conv A   Conversion of integer 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 of integer 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. Therefore they can also contain binary data. Although strings 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 encoded 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:

  • Two backslashes with a sequence of blanks, horizontal tabs, carriage returns and new lines between them are completely ignored. The ignored characters are not part of the string. This can be used to continue a string in the following line. Note that in this case the leading spaces in the new line are not part of the string. Although this possibility exists also for character literals it is mentioned here, since it makes more sense to use it with string literals

Examples of string literals are:

    ""   " "   "\""   "'"   "Gold"   "A\"B !"   "Euro: \8364;"   "CRLF\r\n"

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. The string functions are defined in the library "string.s7i".

    Infix operators:
      &         String concatenation
                  ( "All " & "OK"  "All OK" )
      <&        String concatenation with weak priority
                Overloaded for various types with enable_output or enable_io
                  ( write("i=" <& i digits 2 lpad 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 zeroes
                  ( 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,
                    "abcde"[1]  'a',
                    "abcde"[5]  'e',
                    "abcde"[0]  EXCEPTION RANGE_ERROR,
                    "abcde"[6]  EXCEPTION RANGE_ERROR )
      [ A .. B ] Access a substring from position A to B
                  ( Type of arguments A and B: integer,
                    "abcde"[2 .. 4]  "bcd",
                    "abcde"[2 .. 7]  "bcde",
                    "abcde"[4 .. 2]  "",
                    "abcde"[6 .. 8]  "",
                    "abcde"[-3 .. 4]  "abcd",
                    "abcde"[-3 .. 7]  "abcde",
                    "abcde"[-3 .. 0]  "" )
      [ A len B ] Access a substring from position A with length B
                  ( Type of arguments A and B: integer,
                    "abcde"[2 len 3]  "bcd",
                    "abcde"[2 len 5]  "bcde",
                    "abcde"[-3 len 8]  "abcd",
                    "abcde"[-1 len 9]  "abcde" )
      [ A .. ]  Access a substring beginning at position A
                  ( Type of argument A: integer,
                    "abcde"[3 ..]  "cde",
                    "abcde"[6 ..]  "",
                    "abcde"[-3 ..]  "abcde",
                    ""[1 ..]  "" )
      [ .. A ]  Access a substring ending at position A
                  ( Type of argument A: integer,
                    "abcde"[.. 4]  "abcd",
                    "abcde"[.. 6]  "abcde",
                    "abcde"[.. -3]  "",
                    ""[.. 5]  "" )
    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 )
      rpos(A,B,C) Last 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,
                    rpos("ABCABC",'B', 4)  2,
                    rpos("XYZYX",'Z', 2)  0,
                    rpos("12345",'3', 5)  3 )
      rpos(A,B,C) Last position of char B in string A
                 The search starts at position C of string A
                  ( Type of argument C: integer,
                    Type of result: integer,
                    rpos("ABCABC","BC", 4)  2,
                    rpos("XYZYX","ZY", 2)  0,
                    rpos("12345","34", 5)  3 )
      startsWith(A,B) Determine if a string starts with a prefix.
                  ( Type of result: boolean,
                    startsWith("tmp_s7c.c", "tmp_")  TRUE,
                    startsWith("example", "E")  FALSE )
      endsWith(A,B) Determine if a string ends with a suffix.
                  ( Type of result: boolean,
                    endsWith("hello.sd7", ".sd7")  TRUE,
                    endsWith("A string", "\0;")  FALSE )
      equalAtIndex(A,B,C) Check if A has the searched characters B starting from C.
                  ( Type of result: boolean,
                    equalAtIndex("The quick brown fox", "quick", 5)  TRUE,
                    equalAtIndex("axis", "xi", 3)  FALSE )
      replace(A,B,C) Search A for occurrences of B and replace them with C
                  ( replace("old gold", "old", "one")  "one gone" )
      replace2(A,B,C,D) Search A for occurrences of B followed by C and
                replace them with D.
                  ( replace2("x := (*ord*) y;", "(*", "*)", "")  "x :=  y;" )
      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" )
      ltrim(A)   Removes leading spaces and control chars
                  ( ltrim(" /n xyz /r")  "xyz /r" )
      rtrim(A)   Removes trailing spaces and control chars
                  ( rtrim(" /n xyz /r")  " /n 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   Append B to A
                  ( Type of argument B: char,
                    A &:= B  A := A & str(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 baseType elements (including the empty sequence).

For example: array integer describes arrays of integer elements.

An element of an array can be accessed with an integer index. 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. The array functions are defined in the library "array.s7i". Arrays with non-integer index are defined in the library "idxarray.s7i".

    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 ]  Get a sub array from the position A to the position B
                  ( Type of arguments A and B: integer )
      [ A len B ]  Get a sub array from the position A with maximum length B
                  ( Type of arguments A and B: integer )
      [ A .. ]  Get a sub array beginning at position A
                  ( Type of argument A: integer )
      [ .. A ]  Get 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 )
      A &:= B   Append element B to A
                  ( Type of argument B: baseType,
                    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. The elements can be accessed with an index of keyType.

For example: hash [string] integer describes hash tables with integer elements and string keys.

The keyType of a hash needs to provide the functions hashCode and compare. Besides this the keyType can be any type. The hash functions are defined in the library "hash.s7i".

    Constants:
      hashType.EMPTY_HASH  Empty hash table
    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 hash table element
                  ( Type of argument A: keyType,
                    Type of result: baseType )
    Functions:
      length(A) Number of elements in hash table A
                  ( Type of result: integer,
                    length(hashType.EMPTY_HASH)  0 )
      keys(A)   Unsorted array of keys from hash table A
                  ( Type of result: array keyType )
      values(A) Unsorted array of values from hash table 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 hash table A
                  ( Type of argument B: keyType,
                    Type of argument C: baseType )
      excl(A,B) Exclude element B from hash table A
                  ( Type of argument B: keyType )
      A @:= [B] C  Assign C to element B of hash table 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). The type set of baseType is defined in the library "set.s7i". This abstract data type decides about the implementation of the set. When baseType values can be mapped to integer with the ord function and ord does never raise an exception the set is implemented as bitset(baseType) (defined in the library "bitsetof.htm"), otherwise the set is implemented as hashset(baseType) (defined in the library "hashsetof.htm"). The type set of integer is an alternate name for bitset, which is defined in the library "bitset.s7i".

    Constants:
      setType.EMPTY_SET  Empty set
      EMPTY_SET  Empty set of the type bitset
    Infix operators:
      |         Union
                  ( {1, 3} | {2, 3}  {1, 2, 3} )
      &         Intersection
                  ( {1, 3} & {2, 3}  {3} )
      -         Difference
                  ( {1, 3} - {2, 3}  {1} )
      ><        Symmetric Difference
                  ( {1, 3} >< {2, 3}  {1, 2} )
      in        Element
                  ( Left argument: baseType,
                    Type of result: boolean )
      not in    Is not Element
                  ( Left argument: baseType,
                    Type of result: boolean )
    Relations:
      =, <>     Equal and not equal
                  ( Type of result: boolean )
      <=        Subset
                  ( Type of result: boolean,
                    A <= B  TRUE when no element X exists for which
                       X in A and X not in B
                    holds.
                    A <= B  FALSE when an element X exists for which
                       X in A and X not in B
                    holds.
                    setType.EMPTY_SET <= A  TRUE,
                    A <= setType.EMPTY_SET  FALSE for A <> EMPTY_SET,
                    A <= B  B >= A )
      <         Proper subset
                  ( Type of result: boolean,
                    A < B  A <= B and A <> B,
                    setType.EMPTY_SET < A  TRUE for A <> EMPTY_SET,
                    A < setType.EMPTY_SET  FALSE,
                    A < B  B > A )
      >=        Superset
                  ( Type of result: boolean,
                    A >= B  TRUE when no element X exists for which
                       X in B and X not in A
                    holds.
                    A >= B  FALSE when an element X exists for which
                       X in B and X not in A
                    holds.
                    A >= setType.EMPTY_SET  TRUE,
                    setType.EMPTY_SET >= A  FALSE for A <> EMPTY_SET,
                    A >= B  B <= A )
      >         Proper superset
                  ( Type of result: boolean,
                    A > B  A >= B and A <> B,
                    A > setType.EMPTY_SET  TRUE for A <> EMPTY_SET,
                    setType.EMPTY_SET > A  FALSE,
                    A > B  B < A )
    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 )
      str(A)    Conversion to string
                  ( Type of result: string,
                    str(setType.EMPTY_SET)  "{}",
                    str({})  "{}" )
                    str({1, 2})  "{1, 2}" )
      rand      Random element from a set
                The random elements are uniform distributed.
                  ( Type of result: baseType,
                    rand(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 structure 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:
      =, <>
    Functions:
      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. The category functions are defined in the library "category.s7i".

    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 of integer 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,
                    category parse "does not exist"  EXCEPTION RANGE_ERROR )
    Relations:
      =, <>
    Functions:
      ord(A)    Ordinal number
                  ( Type of result: integer )
      str(A)    Conversion to string
                  ( Type of result: string,
                    str(CHAROBJECT)  "CHAROBJECT" )
    Statements:
      for A range B to C do
        D
      end for   Loop over all categories from B to C
                  ( Type of argument D: proc )
      for A range B downto C do
        D
      end for   Loop over all categories from B down to C
                  ( Type of argument D: proc )

5.15 reference

The type reference describes a reference to any object. The reference functions are defined in the library "reference.s7i".

    Constants:
      NIL       Reference to no element.
    Relations:
      =, <>
    Functions:
      category(A) Get the category of the referenced object
                  ( Type of result: category,
                    category(NIL)  EXCEPTION RANGE_ERROR )
      str(A)    Conversion to string
                  ( Type of result: string )
      getType(A) Get the type of the referenced object
                  ( Type of result: type,
                    getType(NIL)  EXCEPTION RANGE_ERROR )
      objNumber(A) Delivers an unique number for each object
                  ( Type of result: integer,
                    objNumber(NIL)  0 )
      isVar(A)  Reference to a variable object
                  ( Type of result: boolean,
                    isVar(NIL)  EXCEPTION RANGE_ERROR )
      formalParams(A) Gets the formal parameters of a function
                  ( Type of result: ref_list,
                    formalParams(NIL)  EXCEPTION RANGE_ERROR )
      localVars(A) Gets the local variables of a function
                  ( Type of result: ref_list,
                    localVars(NIL)  EXCEPTION RANGE_ERROR,
                    localVars(A)  EXCEPTION RANGE_ERROR for category(A) <> BLOCKOBJECT )
      localConsts(A) Gets the local constants of a function
                  ( Type of result: ref_list,
                    localConsts(NIL)  EXCEPTION RANGE_ERROR,
                    localConsts(A)  EXCEPTION RANGE_ERROR for category(A) <> BLOCKOBJECT )
      body(A)   Gets the body of a function
                  ( body(NIL)  EXCEPTION RANGE_ERROR,
                    body(A)  EXCEPTION RANGE_ERROR for category(A) <> BLOCKOBJECT )
      resultVar(A) Gets the result variable of a function
                  ( resultVar(NIL)  EXCEPTION RANGE_ERROR,
                    resultVar(A)  EXCEPTION RANGE_ERROR for category(A) <> BLOCKOBJECT )
      resultInitValue(A) Gets the initialization value of the result
                         object of a function
                  ( resultInitValue(NIL)  EXCEPTION RANGE_ERROR,
                    resultInitValue(A)  EXCEPTION RANGE_ERROR for category(A) <> BLOCKOBJECT )
      arrayToList(A) Return the array elements as list
                  ( Type of result: ref_list,
                    arrayToList(NIL)  EXCEPTION RANGE_ERROR,
                    arrayToList(A)  EXCEPTION RANGE_ERROR for category(A) <> ARRAYOBJECT )
      arrayMinIdx(A) Return the minimal index of an array
                  ( Type of result: integer,
                    arrayMinIdx(NIL)  EXCEPTION RANGE_ERROR,
                    arrayMinIdx(A)  EXCEPTION RANGE_ERROR for category(A) <> ARRAYOBJECT )
      arrayMaxIdx(A) Return the maximal index of an array
                  ( Type of result: integer,
                    arrayMaxIdx(NIL)  EXCEPTION RANGE_ERROR,
                    arrayMaxIdx(A)  EXCEPTION RANGE_ERROR for category(A) <> ARRAYOBJECT )
      structToList(A) Return the struct elements as list
                  ( Type of result: ref_list,
                    structToList(NIL)  EXCEPTION RANGE_ERROR,
                    structToList(A)  EXCEPTION RANGE_ERROR for category(A) <> STRUCTOBJECT )
      interfaceToStruct(A) Return the struct to which the interface object points.
                  ( interfaceToStruct(NIL)  EXCEPTION RANGE_ERROR,
                    interfaceToStruct(A)  EXCEPTION RANGE_ERROR for category(A) <> INTERFACEOBJECT )
      file(A)   File name of the referenced object
                  ( Type of result: string,
                    file(NIL)  EXCEPTION RANGE_ERROR )
      line(A)   Line number of the referenced object
                  ( Type of result: integer,
                    line(NIL)  EXCEPTION RANGE_ERROR )
      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(NIL, reference)  EXCEPTION RANGE_ERROR,
                    getValue(A, reference)  EXCEPTION RANGE_ERROR for
                        category(A) not in {FWDREFOBJECT, REFOBJECT, REFPARAMOBJECT, RESULTOBJECT,
                        LOCALVOBJECT, ENUMLITERALOBJECT, CONSTENUMOBJECT, VARENUMOBJECT} )
      getValue(A, ref_list) Dereference as ref_list
                  ( Type of result: ref_list,
                    getValue(NIL, ref_list)  EXCEPTION RANGE_ERROR,
                    getValue(A, ref_list)  EXCEPTION RANGE_ERROR for
                        category(A) not in {MATCHOBJECT, CALLOBJECT, REFLISTOBJECT} )
      getValue(A, integer) Dereference as integer
                  ( Type of result: integer,
                    getValue(NIL, integer)  EXCEPTION RANGE_ERROR,
                    getValue(A, integer)  EXCEPTION RANGE_ERROR for category(A) <> INTOBJECT )
      getValue(A, bigInteger) Dereference as bigInteger
                  ( Type of result: bigInteger,
                    getValue(NIL, bigInteger)  EXCEPTION RANGE_ERROR,
                    getValue(A, bigInteger)  EXCEPTION RANGE_ERROR for category(A) <> BIGINTOBJECT )
      getValue(A, float) Dereference as float
                  ( Type of result: float,
                    getValue(NIL, float)  EXCEPTION RANGE_ERROR,
                    getValue(A, float)  EXCEPTION RANGE_ERROR for category(A) <> FLOATOBJECT )
      getValue(A, char) Dereference as char
                  ( Type of result: char,
                    getValue(NIL, char)  EXCEPTION RANGE_ERROR,
                    getValue(A, char)  EXCEPTION RANGE_ERROR for category(A) <> CHAROBJECT )
      getValue(A, string) Dereference as string
                  ( Type of result: string,
                    getValue(NIL, string)  EXCEPTION RANGE_ERROR,
                    getValue(A, string)  EXCEPTION RANGE_ERROR for category(A) <> STRIOBJECT )
      getValue(A, bitset) Dereference as bitset
                  ( Type of result: bitset,
                    getValue(NIL, bitset)  EXCEPTION RANGE_ERROR,
                    getValue(A, bitset)  EXCEPTION RANGE_ERROR for category(A) <> SETOBJECT )
      getValue(A, clib_file) Dereference as clib_file
                  ( Type of result: clib_file,
                    getValue(NIL, clib_file)  EXCEPTION RANGE_ERROR,
                    getValue(A, clib_file)  EXCEPTION RANGE_ERROR for category(A) <> FILEOBJECT )
      getValue(A, program) Dereference as program
                  ( Type of result: program,
                    getValue(NIL, program)  EXCEPTION RANGE_ERROR,
                    getValue(A, program)  EXCEPTION RANGE_ERROR for category(A) <> PROGOBJECT )
      getValue(A, ACTION) Dereference as ACTION
                  ( Type of result: ACTION,
                    getValue(NIL, ACTION)  EXCEPTION RANGE_ERROR,
                    getValue(A, ACTION)  EXCEPTION RANGE_ERROR for category(A) <> ACTOBJECT )
      getValue(A, type) Dereference as type
                  ( Type of result: type,
                    getValue(NIL, type)  EXCEPTION RANGE_ERROR,
                    getValue(A, type)  EXCEPTION RANGE_ERROR for category(A) <> TYPEOBJECT )
      compare(A, B) Compare function
                  ( Type of result: integer )
      hashCode(A) Hash function
                  ( Type of result: integer )
    Statements:
      setVar(A, B) Set var flag of referenced object A to B
                  ( Type of argument B: boolean,
                    setVar(NIL, B)  EXCEPTION RANGE_ERROR )
      setCategory(A, B) Set the category of the referenced object A to B
                  ( Type of argument B: category,
                    setCategory(NIL, B)  EXCEPTION RANGE_ERROR )
      setType(A, B) Set the type of the referenced object A to B
                  ( Type of argument B: type,
                    setType(NIL, B)  EXCEPTION RANGE_ERROR )
      setValue(A, B) Set the value of the referenced object A to B
                  ( Type of argument B: ref_list )
      setFormalParams(A, B) Set the formal parameters of a function
                  ( Type of argument B: ref_list,
                    setFormalParams(NIL, B)  EXCEPTION RANGE_ERROR )

5.16 ref_list

The type ref_list describes a list of reference objects. The ref_list functions are defined in the library "ref_list.s7i".

    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:
      =, <>
    Functions:
      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,
                    A @:= [B] C 
                        A := A[..pred(B)] & make_list(C) & A[succ(B)..],
                    A @:= [0] C  EXCEPTION RANGE_ERROR,
                    A @:= [succ(length(A))] C  EXCEPTION RANGE_ERROR )
      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. The program functions are defined in the library "progs.s7i".

    Constants:
      program.EMPTY  Empty program.
    Relations:
      =, <>
    Functions:
      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 B: reference )
      sysVar(A, B)  Return a reference of the system var B of program A
                  ( Type of result: reference,
                    Type of argument B: string )
      errorCount(A)  Number of errors in the program A
                  ( Type of result: integer )
      globalObjects(A)  List of global defined objects in the program A
                  ( Type of result: ref_list )
      syobject(A, B)  Return object with name B in program A
                  ( Type of result: reference,
                    Type of argument B: string )
      match(A, B)  Return object from program A which matches B
                  ( Type of result: reference,
                    Type of argument B: ref_list )
    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 functions str and parse 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:
      =, <>, <, <=, >, >=
    Functions:
      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))) )
      compare(A, B) Compare function
                  ( Type of result: integer )
      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.20 color

The type color describes colors. The color functions are defined in the library "color.s7i".

    Elements:
      var integer: red_part is 0;
      var integer: green_part is 0;
      var integer: blue_part is 0;
    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 )
      gray(BR)  Create a gray color value from BR
                  ( Type of argument BR: integer )
      compare(A, B) Compare function
                  ( Type of result: integer )
      hashCode(A) Hash function
                  ( Type of result: integer )

5.21 time

The type time describes times and dates. For dates the proleptic Gregorian calendar is used (which assumes that the Gregorian calendar was even in effect at dates preceding its official introduction). This convention is used according to ISO 8601 which also defines that positive and negative years exist and that the year preceding 1 is 0. Time is measured in hours, minutes, seconds and micro seconds. Additionally information about the difference to UTC and a flag indicating daylight saving time is maintained also. The time functions are defined in the library "time.s7i".

    Elements:
      var integer: year is 0;
      var integer: month is 1;
      var integer: day is 1;
      var integer: hour is 0;
      var integer: minute is 0;
      var integer: second is 0;
      var integer: micro_second is 0;
    Infix operators:
      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 )
      strDate(A)  Conversion of the date to string
                  ( Type of result: string )
      strTime(A)  Conversion of the daytime to string
                  ( Type of result: string )
      strTimeZone(A)  Conversion of the time zone to string
                  ( Type of result: string )
      truncToSecond(A)  Truncate a time to a second
      truncToMinute(A)  Truncate a time to a minute
      truncToHour(A)  Truncate a time to a hour
      truncToDay(A)  Truncate a time to a day
      truncToMonth(A)  Truncate a time to a month
      truncToYear(A)  Truncate 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 )
      daysInYear(Y)  Calculate the number of days in a year
                  ( Type of argument Y: integer,
                    Type of result: integer )
      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 )
      daysInMonth(A)  Calculate the number of days in a month
                  ( 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(Y, D)  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 argument Y: integer,
                    Type of argument D: integer,
                    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 )
      toUTC(A)  Conversion to Coordinated Universal Time (UTC)
      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 )
      timestamp1970(A)  Time expressed in seconds since the
                Unix Epoch (1970-01-01 00:00:00 UTC)
                  ( Type of result: integer )
      timestamp1970ToTime(A)  Convert a timestamp into a time from
                the local time zone
                  ( Type of argument A: integer )
      compare(A, B)  Compare function
                  ( Type of result: integer )
      hashCode(A)  Hash function
                  ( Type of result: integer )
    Statements:
      await(A)  Wait until the given time

5.22 duration

The type duration describes time and date durations. The duration functions are defined in the library "duration.s7i".

    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 )
      +         Add a duration to a time
                  ( Type of left operand: time,
                    Type of result: time )
      -         Subtract a duration from a time
                  ( Type of left operand: time,
                    Type of result: time )
      -         Subtract two times
                  ( Type of left operand: time,
                    Type of right operand: time )
      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:
      getYears(A)  Obtains the years of a duration
                  ( Type of result: integer )
      getMonths(A) Obtains the months of a duration
                  ( Type of result: integer )
      getDays(A)   Obtains the days of a duration
                  ( Type of result: integer )
      getHours(A)  Obtains the hours of a duration
                  ( Type of result: integer )
      getMinutes(A) Obtains the minutes of a duration
                  ( Type of result: integer )
      getSeconds(A) Obtains the seconds of a duration
                  ( Type of result: integer )
      getMicroSeconds(A)  Obtains the micro seconds of a duration
                  ( Type of result: integer )
      toYears(A)  Return the duration in years
                  ( Type of result: integer )
      toMonths(A) Return the duration in months
                  ( Type of result: integer )
      toDays(A)   Return the duration in days
                  ( Type of result: integer )
      toHours(A)  Return the duration in hours
                  ( Type of result: integer )
      toMinutes(A) Return the duration in minutes
                  ( Type of result: integer )
      toSeconds(A) Return the duration in seconds
                  ( Type of result: integer )
      toMicroSeconds(A)  Return the duration in micro seconds
                  ( 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:
      A +:= B   Increment A by B
                  ( A +:= B  A := A + B )
      A -:= B   Decrement A by B
                  ( A -:= B  A := A - B )
      A +:= B   Increment time A by B
                  ( Type of argument A: time,
                    A +:= B  A := A + B )
      A -:= B   Decrement time A by B
                  ( Type of argument A: time,
                    A -:= B  A := A - B )
      wait(A)   Wait for given duration

For the operations - (negate a duration) and - (subtract two time values) holds:

    (tim1 - tim2) = - (tim2 - tim1)

For the operations + (add a duration to a time) and - (subtract two time values) holds:

    tim2 + (tim1 - tim2) = tim1

For the operations - (subtract a duration from a time) and - (subtract two time values) holds:

    tim1 - (tim1 - tim2) = tim2

5.23 file

The type file is the interface type for sequential files. The file functions are defined in the library "file.s7i".

    Variables:
      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
      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 )
      openUtf8(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 )
      openUtf16(A, B) Open external UTF-16 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 )
      popen8(A, B) Open a UTF-8 pipe to a process
                  ( Type of argument A: string,
                    Type of argument B: string,
                    Type of result: file,
                    Returns STD_NULL if popen8 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 )
      compare(A, B) Compare function
                  ( Type of result: integer )
      hashCode(A) Hash function
                  ( Type of result: integer )
    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, 0)  EXCEPTION RANGE_ERROR )

5.24 text

The type text describes two dimensional files. The text functions are defined in the library "text.s7i".

    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
      clear(A, UP, LO, LE, RI)  Clear an area of the window
                  ( Type of argument UP: integer
                    Type of argument LO: integer
                    Type of argument LE: integer
                    Type of argument RI: integer )
      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: resultVariable is baseType.value;
      begin
        statements
      end func
                Create a baseType function
                  ( Type of 'statements': proc,
                    Type of result: func baseType )

      func
      result
        var baseType: resultVariable 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: tak is 0;
  begin
    if y >= x then
      tak := z;
    else
      tak := 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: conjunction is FALSE;
  begin
    if first then
      conjunction := second;
    end if;
  end func;

Here the second parameter is only evaluated when the first parameter is TRUE.

5.26 varfunc

The 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 void

The 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:
      str(A)    Conversion to string
                  ( Type of result: string )
      newtype   Create a new type
      gentype   Generate a type
      gensub(A) Generate a subtype
      typeof(A) Get the type of an expression
                  ( Type of argument A: Defined for all types,
                    typeof(1)  integer,
                    typeof("asdf")  string )
      isFunc(A)  Is this type a func type
                  ( Type of result: boolean,
                    isFunc(func char)  TRUE,
                    isFunc(varfunc char)  FALSE )
                    isFunc(char)  FALSE )
      isVarfunc(A)  Is this type a varfunc type
                  ( Type of result: boolean,
                    isVarfunc(func char)  FALSE,
                    isVarfunc(varfunc char)  TRUE,
                    isVarfunc(char)  FALSE )
      resultType(A)  Get the result type of a func or varfunc type
                  ( resultType(func char)  char,
                    resultType(proc)  void,
                    resultType(integer)  EXCEPTION RANGE_ERROR )
      isDerived(A)  Is this type derived from another type
                  ( Type of result: boolean,
                    isDerived(subtype char)  TRUE )
      meta(A)       Get the type from which type A is derived
                  ( meta(subtype char)  char )
      base_type(A)  Get the base type of an array, pointer or
                    set type
                  ( base_type(array char)  char,
                    base_type(ptr string)  string,
                    base_type(set of integer)  integer )
      typeNumber(A)  Get an unique number for a type
                  ( Type of result: integer )
      typeObject(A)  Get a unique object (match object) of a type
                  ( Type of result: reference )
      compare(A, B) Compare function
                  ( Type of result: integer )
      hashCode(A) Hash function
                  ( Type of result: integer )
    Statements:
      addInterface(A, B)  Adds the interface type B to the implementation type A
      const aType: name is value
                Declare constant 'name' with 'value'
      var aType: name is value
                Declare variable 'name' with 'value'

5.30 object

The type object is used as meta type for various types. This allows defining common operations for all this types. The type object is not used as element type for container classes since this can be done much better and type safe with abstract data types like array, set, hash and others.

    Functions:
      TRACE_OBJ(A)  Write internal information

5.31 expr

The type expr is used to describe unmatched expressions. These are expressions where the recognizing of the functions and the type check is not done yet. This is used for example in the definition of function bodies.

    Functions:
      WRITE_EXPR(A)
                Write expr A to FILE OUT


 previous   up   next