How do the conditions work and how can they be optimized to improve performance?
condition in all functions where they are present are executed from left to right. The next one is executed only if the previous one evaluated to true.
Therefore, condition should be arranged in ascending order of the expected load.
How to use comparisons to optimize the calculation load?
If you have a large code that consumes a lot of resources, you can check whether the necessary inputs for it have changed by using the previous value.
For example, we concatenated all the tracked fields using listCreate into a technical field control_field and check if it has changed using the previous value of the field:
=: if(condition: #old.control_field == #control_field; then: $#onfv; else: $calc)
calc: "..."
If it hasn't changed, we do not compute calc, but take the previous value of the current field.
What does Cond always return?
There is a sugar cond — it always returns the result of the comparison inside itself — true or false.
In cond, conditions and, or, and groupings () are possible:
&& — and.
|| — or.
Cond can be used inside functions, and inside condition you can avoid unnecessary comparisons:
=: if(condition: cond`$line_1 != 0 || $line_2 != 0`; then: 100; else: 0)
line_1: 10
line_2: 0
// Result = 100
In words, this example states: if line_1 is not equal to 0 or line_2 is not equal to 0, then 100, otherwise 0.
Is it possible to use cond inside condition without additionally specifying = true/false?
Yes. condition accepts true or false in addition to comparisons:
=: if(condition: $cond; then: 100; else: 0)
cond: if(condition: $line_1 != 0; then: true; else: false)
line_1: 10
// Result = 100
How do I write the condition and?
&& — and.How to write a condition or?
|| — or.What are the brackets inside cond used for?
For grouping conditions:
cond: cond`($A=1 && $B=1) || ($A=2 && $B=2)`
// Means: A and B are equal to 1 or A and B are equal to 2
At what point does cond end?
When all conditions at the same level are met as true:
cond: cond`($A=1 && $B=1) || ($A=2 && $B=2)`
// Here the execution will end if A=1 and B=1, there will be no repeated reference to A and B