-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parameter expressions #3
Comments
Problem 1: Exponent expressionsIf the feature is implemented such that sub-expressions are valid arguments for exponent powers, it is possible that a user may pass an expression which, while not preceded with a minus, still evaluates to a negative. For example: While disallowing exponents to contain parentheses may work, it might also reduce the overall utility of the application. Problem 2: Inconsistent application of rules between fractions and exponentsThe very fact that exponents would be permitted in parameter expressions creates some inconsistency in rules. Whether they are allowed or not, their problems mirror those of fractions. Specifically, consider the arguments against inclusion of fractions in parameters:
And then consider the arguments regarding inclusion of exponents in parameters:
While exponents create fewer overall issues than fractions, they have the potential to directly create fractions, while simultaneously sharing (arguably) the most important reason against including fractional parameters. |
Problem 3: Parentheses in parameter expressionsWhile I am certain that parentheses in parameter expressions would be extremely useful, there are some reasons I think they should not be added.
|
Parameter expressions
A highly useful feature currently implemented in AlgebraBalancer is the ability to write expressions in the parameter inputs, which are evaluated before being passed to calculations.
In AlgebraBalancer, this feature is safe because it uses DataTable, which evaluates specifically math and not code. I'm unsure whether a similar feature exists in Node, and I definitely want to avoid giving the user access to potentially dangerous options like
eval()
.In order to enforce the desired safety, it may be necessary to write a custom math evaluation function which sanitizes inputs before passing them to
Function()
.The sanitized inputs might be checked by matching them against a regex pattern. There could also be a second pattern (breaking them up to simplify the overall pattern) for checking that parentheses are balanced, if any are detected in the pattern.
While exponents in parameter expressions are not supported in AlgebraBalancer, I believe they should be in this project considering the evaluator will be custom and can be made to map operations to their respective functions.
Negative exponents in parameter expressions should be disallowed. At the time of writing, it is an unwritten guideline for this project that parameters may not contain fractions nor radicals; only integers and math which simplifies to integers.
Division is not currently an expectation of the feature. Testing to confirm that the result doesn't resolve to a fraction nor undefined may be more effort than it is worth. It would also be frustrating to users for rule-following expressions to simply not evaluate sometimes.
The text was updated successfully, but these errors were encountered: