feat: add d2:log and d2:exponent to program rule grammar#101
Conversation
d2:log and d2:pow to program rule grammard2:log and d2:exponent to program rule grammar
| NamedFunction.isNull -> functions.isNull(evalToMixed(fn.child(0))) | ||
| NamedFunction.least -> functions.least(evalToNumbers(fn.children())) | ||
| NamedFunction.log -> if (fn.size() == 1) functions.log(evalToNumber(fn.child(0))) | ||
| NamedFunction.log, NamedFunction.d2_log -> if (fn.size() == 1) functions.log(evalToNumber(fn.child(0))) |
There was a problem hiding this comment.
Is there a reason to add d2:log when log already exists?
There was a problem hiding this comment.
The reason is that all other program rule functions use the d2:-prefix.
There was a problem hiding this comment.
Was this discussed to keep it consistent? Maybe @enricocolasante knows?
There was a problem hiding this comment.
I would say so.
At the moment rule-engine is only allowing CommonD2Functions and RuleEngineD2Functions and all of them have the d2 prefix.
There wasn't a real discussion about it. We already have some generic functions about numeric operations like modulus or floor using the d2 prefix and as always this argument is the one used to continue doing this way.
I think at some point we should separate generic functions and custom DHIS2 functions, the question is: should we do it now?
There was a problem hiding this comment.
Maybe not the best time to do another refactor of the language(s) on a more fundamental level so if enrico is happy with this PR I think we try to move it forward
- Edit author - Correction of the test title - Adds a test case for exponent > 1 and exponent < 0
Also add missing case for negative exponent
|

Things to look at:
logfunction inCalculator.kt, and I just copy-pasted the implementation. A more clever solution might exist.powfor "raising a number to a power", and I think C++ uses the same name. Personally I associate this operation more with the nameexp. The advocates forpowprobably argue thatexpis another function (e^x). Regardless, I tend to look upexprather thanpowif I want to "exponentiate" something, and chances are this is true for other people as well.Update:
logandd2_log.powtoexponent(as suggested in the roadmap).