Clarify whether `x` is allowed to denote the identity function and support if so
- Dominant language
- JavaScript
- Stars
- 15.1k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Description
> Btw. is it intended that "map([], f(x)=x)" throws the index error (which is fixed now), but the short form "map([], x)" will give a "undefined symbol x" error? "map([], x+1)" was always okay, as it is parsed as a function, and worked even without the fix. Otherwise this short term just seems to be limited, compared with a declared function.
_Originally posted by @NilsDietrich in [#3564](https://github.com/josdejong/mathjs/issues/3564#issuecomment-3470382732)_
The above question seems not to have to do with the empty first operand, but simply whether a bare variable is allowed in the "compiled inline expression" in the mathjs expression language parser. Currently, attempting to do so fails with an "undefined symbol" error. So we should either:
1. Support a single bare variable as the identity function wherever a "compiled inline expression" is allowed (currently just three places, namely the callback argument of `map`, `foreach`, or `filter`), or
2. Decide that it is not supported and adjust the documentation accordingly, and ideally generate a more specific error message.
I'd say all else being equal, (1) seems preferable, just on the principle of minimizing exceptions to rules. But it is up to @josdejong. If (1) is decided on, this should be changed to a "bug" issue; if (2) then a "documentation" issue.
Contributor guide
Assessment
This issue has not been assessed yet.