"Blackboard" Calculator

Once keyword




The recurrence formulas and the initial values ​​corresponding to them are located in different parts of the program: the formulas are inside the cycle, and the initial values ​​are outside. In the Blackboard calculator, you can combine them using the once keyword once(expression). For example, the recurrence formula n = n+1 and the initial value x = 0 can be combined into the formula n = once(0)+1.

Formally, the once keyword is a function that, upon first access to it, returns the value of its argument, and on subsequent calls, the current value of the variable that it initiated. Thus, the example of the previous paragraph with the calculation of the sum of squares can be written as follows:

 do
n = once(0)+1
    S = once(0)+n^2
until(n = 10)

    Although this form of writing recurrence formulas is more compact (all in one place) and is shorter, then the traditional form will be used.