How many times will a line of code be calculated if there are 3 references to it in the code?
3 (three)! But only if the string is not fixed.
What does this mean? If we have the following code:
=: if(condition: $calc < 0; then: 0; else: $calc)
calc
// And further in calc, a calculation over 40 lines
then during its execution, the machine will reach the first calc, go and compute it, then it will reach the second call to calc in the line with if and go compute it again!
To indicate that it should not be computed a second time, ~ is used:
=: if(condition: $calc < 0; then: 0; else: $calc)
~calc
// And further in calc, a calculation over 40 lines
In this case, when calc is computed the first time, it will be remembered (fixed) within the execution of this code, and a repeated reference to it in else will not lead to a repeated computation.
How do I fix the value of a string in the first calculation, so that the next calls take the memorized value?
You need to place ~ before the line name:
=: if(condition: $select != ""; then: $select; else: 0)
~select: select(table: 'table_name'; field: 'field_name'; where: 'id' = #number)
In what cases can this lead to a calculation error?
For example, in while or listReplace. That is, where there are iterations. If you fix the string on the first iteration, the subsequent ones will not be calculated:
= : while(action: $set; limit: 30; iterator: "iter1")
set: var(name: "count"; value: $plus)
plus: listAdd(list: $var; item: $i)
var: var(name: "count"; default: $#lc)
i: dateAdd(date: $#nd; days: $days; format: "Y-m-d")
days: $#iter1 * -1
// This code creates a list of 30 dates, starting from the current date and going back 30 days.
// A tilde (~) anywhere in it will break it!