"Blackboard" Calculator

Debugging the Application




Debugging formulas in the Blackboard calculator is facilitated by the fact that the calculator displays messages about most possible syntax errors and even on some runtime errors (division by 0, the logarithm of a negative number, etc.).

In addition, debugging capabilities are expanded due to the specifics of the calculator, which, at the end of the count, displays the values ​​of the expressions in their right part below the formulas. But only those that were calculated immediately before the completion of the calculations. For example, the variable n in the listing below is not visible, since it was calculated before the start of the loop. The variable m inside the loop is also not visible, since after the last check of the loop condition its body was not executed.

n = sin(pi/2)
m = 0
while(m<10)
    m = m+1
wend

Such a calculator action algorithm is explained by the fact that it makes sense to display only the last, final values ​​of the variables. This circumstance can be used by adding debug lines of type "= variable_name". Continuing the previous example, add these lines and run the calculation:

m = 0
while(m<10)
    m = m+1
wend
= n
1
= m
10

The stop keyword.

To look at the values ​​of expressions at any time, and not just at the end of calculations, you need to use the stop(condition) keyword, which stops the loop when the condition is satisfied. For example, stop(True) stops the loop after each step. In the following example, after stopping by condition, only the expressions counted in the body of the loop are visible, and their past values, and even more so the future ones, are not visible:

n = sin(pi/2)
m = 0
while(m<10)
    m = m+1
    3
    stop(m = 3)
    -> Циклические вычисления остановлены по условию
    n = n-1
    -2
wend
= m
= n

In the case of stopping calculations with the stop keyword, the loop step is completed. This means that the calculator processes the entire body of the loop, and not just the formulas preceding the stop keyword. For example, in the considerule example, when stopping, it calculates not only the variable m that precedes the stop keyword, but also the variable n that comes after.

Tip. After stopping by the stop keyword, the calculating can be continued by clicking the "Start" button. Moreover, the calculation can be continued by changing the stopping condition.