The simplest way to create a tuple, as mentioned in section “Control Types and Constants”, is the use of constants together with the operator assign (or in case of iconic data one of its equivalents shown in table 8.7):
assign ([],empty_tuple) assign (4711,one_integer) assign ([4711,0.815],two_numbers)
This code is displayed as
empty_tuple := [] one_integer := 4711 two_numbers := [4711,0.815]
This is useful for constant tuples with a fixed (small) length. More general tuples can be created by successive application of the concatenation or the operator assign_at together with variables, expressions or constants. If we want to generate a tuple of length 100, where each element has the value 4711, it might be done like this:
tuple := []
for i := 1 to 100 by 1
tuple := [tuple,4711]
endfor
Because this is not very convenient a special function called gen_tuple_const is available to construct a tuple of a given length, where each element has the same value. Using this function, the program from above is reduced to:
tuple := gen_tuple_const(100,4711)
A fast way to create a sequence of values with a common increment is to use tuple_gen_sequence. For example, to create a tuple containing the values 1..1000, use
tuple_gen_sequence(1,1000,1,Sequence)
An alternative syntax to the above is to write:
Sequence := [1:1:1000]
If the increment value is one (as in the above example), it is also possible to write:
Sequence := [1:1000]
If we want to construct a tuple with the same length as a given tuple there are two ways to get an easy solution. The first one is based on gen_tuple_const:
tuple_new := gen_tuple_const(|tuple_old|,4711)
The second one is a bit tricky and uses arithmetic functions:
tuple_new := (tuple_old * 0) + 4711
Here we get first a tuple of the same length with every element set to zero. Then, we add the constant to each element.
In the case of tuples with different values we have to use the loop version to assign the values to each position:
tuple := []
for i := 1 to 100 by 1
tuple := [tuple,i*i]
endfor
In this example we construct a tuple with the square values from 12 to 1002.