Many if not most control loops in programming require an initialisation step that precedes the looping itself. For instance, if we want to find the minimum value of a list, array, or set of numbers, we need to initialise the value to be saved as the minimum to start as infinity or some particular value that is sure to be larger than any value in the set. It is quite common to forget the initialisation step when coding. In cases when the variable already has a value because of previous use, this can create a sometimes difficult-to-track logical error.
At the same time, the syntax of loop structures usually needs typing in the initialisation step that is not—as we shall see—actually required by the looping schema per se. We introduce the commands initialise and initialize which make their arguments a special value initial which is a typeless, null or identity element which becomes typed only when it is updated or operated on. The typing then depends on the operation used. When it is printed, it produces the character string of its own variable name. But, if a numerical value is added to it, it is behaves like a zero so that the result is just the sum of the addends. If it is used in a min operation, it behaves as though its value had been infinity. Initial values thus have many faces depending on the operation:
add 0 (zero)
subtract 0 (zero)
multiply 1 (one)
divide 1 (one)
minimum inf (infinity)
maximum -inf (minus infinity)
comparison vacuous (all possible values)
append null (empty list)
envelope empty (empty set [inf, -inf])
intersect vacuous (all possible values)
union empty (empty set [inf, -inf])
intersection vacuous (all possible values)
concatenate "" (null string)
print <variable's name>
Thus the use of initial values can be quite varied:
initialise(m); for f in elements : m = m + 1 # count
initialise(m); for f in elements : m += 1 # count
initialise(m); for f in elements : m = m + f # sum
initialise(m); for f in elements : m = m * f # product
initialise(m); for f in elements : m = min(m, f) # min
initialise(m); for f in elements : if f < m : m = f # min [see how below]
initialise(m); for f in elements : m = envelope(m, f) # convex hull
initialise(m); for f in elements : m = intersect(m, f) # intersection
initialise(m); for f in elements : m = m.union({f}) # set union
initialise(m); for f in elements : m = m.intersection(f) # set intersection
initialise(m); for f in elements : m = concatenate(m, f) # string or list concatenation
You can initialise several variables at once:
initialise(m, k); for f in elements :
m = envelope(m, f)
k = intersect(k, f)
When an initial value is used in a comparison with <, >, >=, <=, or ==, it has the face value of all possible values, and thus when this comparison is used in a conditional expression or conditional statement, the condition will always be (at least partially) true so the rule fires and the consequent is executed.
If you first add numerical values and then try to concatenate strings to something that was originally initial, ordinary type conflicts can arise and default behaviours should follow. In R, that would be type elevation
c(1,3,4,5) # 1 3 4 5
c(1,3,4,5, '6') # "1" "3" "4" "5" "6"
while, in Python, it would be
[1,3,4,5] # [1, 3, 4, 5]
[1,3,4,5, '6'] # [1, 3, 4, 5, '6']