mathjs lacks a notation to enforce function call interpretation rather than scalar multiplication #3358
Replies: 3 comments 2 replies
-
|
Interestingly, the HISTORY entry for v3.16.1 shows |
Beta Was this translation helpful? Give feedback.
-
|
See also #3379 for other ideas on what notation might be used to allow these sorts of "computed" function calls. |
Beta Was this translation helpful? Give feedback.
-
|
I think we had to drop support for This discussion overlaps with #3379 (comment), shall we continue the discussion there? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
At the moment, suppose you import an object
foointo mathjs that has a method.operator()that returns a function, and you want to call that function on the argument2. You might reasonably write the mathjs expression-language codefoo.operator()(2). However, you will be disappointed: that is parsed as multiplying the result offoo.operator()by 2.As far as I can tell, there is no mathjs expression language notation that makes something like this parse as a function call. Even most workarounds like
map([2], foo.operator())[1]ormatrixFromFunction([2],foo.operator())[2]don't work -- they complain thatfoo.operator()has no free variable -- mathjs won't just trust that maybefoo.operator()returns a function and give one of these a shot. You can work around this with something likecall(f, x) = f(x); call(foo.operator(), 2)but then you have to deal with ResultSets (see #3355 for some discussion on that).It seems to me important to have a notation for calling an entity as a function on some arguments. We could have something like
call(f, arg1, arg2, ..., argN)so that in this case we would writecall(foo.operator(), 2). And/or we could adopt some notation to be unambiguous for function call. For example, we could adopt the Haskell function call notationf $ arg1 arg2...so that in this case we would writefoo.operator() $ 2. Or we could say that if the argument list has commas in it, likef(a,b), that's always a function call, and to force a unary function call like this, you would writefoo.operator()(2,). Or we could have some special delimiters, like maybe double parentheses, that always mean function call, so you could writefoo.operator()((2)).Of these options, I think I like
foo.operator()(2,)the best. But there are likely other ways to address the need to allow calling a function that happens to be returned from an expression (rather than already being a name or a function definition). What are your thoughts? I am happy to do a PR if we can reach a consensus here, as it would be a real help for another project to have such a notation.Beta Was this translation helpful? Give feedback.
All reactions