Description
Note: This is related to #154, but I think smaller in scope and could be handled separately if this is decided to be a good idea.
I've noticed that all typed functions have length 2. For example:
const f = math.evaluate('f(w,x,y,z) = w*x*y*z')
console.log(f.length) // 2
whereas I would expect f.length
to be 4.
Suggestion:
- if a typed function has only one signature, its length should be the length of that signature.
- alternatively the length of a typed function should be the length of its first signature.
Notes:
-
Provide some API to access the currently-defined types #154 seems very useful, but I think that having a reasonable length property would also be useful. It would make typed functions behave more like "normal" js functions. Additionally, there's less (imo) of a design issue here since the API would be much simpler.
-
My particular motivation is to supply a random sample to the result of
math.evaluate
so I can tell if evaluating the function would result in an error. For example,const f = math.evaluate(f(x) = 2^[1,2,3])
evaluates fine. but callingf(anything)
will throw an error. For this purple, having a valid sample in f's domain isn't really necessary (evaluating to NaN would be fine) but I do need to know how many params it has.My current workaround is getting the number of params from the FunctionAssignmentNode, but I'd prefer to implement the "sample evaluation of f" logic in a way that is agnostic as to whether
f
is coming from MathJs or from some other source.