This feature would be really useful. I feel the need for it very often. So I started implementing it in Zest.js, I would like to share and propose a few things from my experience.
{
"variableName": <varName>,
"operandA": <varName/number>,
"operandB": <varName/number>,
"operation": <"add"/"subtract"/"multiply"/"divide">,
"index": <number>,
"enabled": <boolean>,
"elementType": "ZestAssignCalc"
}
Here,
"variableName" is the variable where the result of the operation would be stored. The result would be a string. Since we don't have a ZestAssignInteger or a similar statement, we have to store the result in variable as a string. (Needs more discussion)
"operandA" is the first operand of the binary operation. This would be a variable name or a number.
"operandB" is the second operand of the binary operation. This would also be a variable name or a number.
"operation" is the operator of the binary operation. This could be add, subtract, multiply and divide.
Example:
{
"variableName": "m",
"operandA": "m",
"operandB": 1,
"operation": "add",
"index": 12,
"enabled": true,
"elementType": "ZestAssignCalc"
}
In the above example statement, we have a variable `m` with some initial value, `operandA` the first operand as `m`, `operandB` the second operand as 1 and `operation` as "add". The above statement would increment `m` by 1.
This has worked pretty well for performing binary arithmetic operations. We sure can add more operations to it like the modulo operation, exponent operation, etc once we agree on a given form.
I would like to know what others think of this proposed json form for ZestAssignCalc. Maybe suggest some better attribute names for operands and operation?