Replies: 5 comments 1 reply
-
I think this is a duplicate of #1414. It will take a bit of effort. |
Beta Was this translation helpful? Give feedback.
-
@josdejong thanks for the link that makes sense. Maybe the library should contain a convenience function, since this could be useful in many projects. |
Beta Was this translation helpful? Give feedback.
-
After some testing, I don't see how #1414 can solve this. e.g. {
"mathjs": "OperatorNode",
"op": "*",
"fn": "multiply",
"args": [
{
"mathjs": "SymbolNode",
"name": "var"
},
{
"mathjs": "SymbolNode",
"name": "pi"
}
],
} Both nodes |
Beta Was this translation helpful? Give feedback.
-
You can check whether the symbol is defined or not, for example: function isDefined(symbol) {
return math.expression.mathWithTransform[symbol] !== undefined || math.Unit.isValuelessUnit(symbol)
}
isDefined('pi') // true
isDefined('var') // false
isDefined('foo') // false
isDefined('millimeter') // true |
Beta Was this translation helpful? Give feedback.
-
@josdejong that would also report e.g. |
Beta Was this translation helpful? Give feedback.
-
e.g. the user may enter a formula like
2 * scale * pi * + offset
pi
is known by MathJsHow can we easily get a list of all unknown variables?
i.e. we can evaluate the expression with an empty scope and it will throw - but this will only return the first undefined symbol
Beta Was this translation helpful? Give feedback.
All reactions