Skip to content

Clarify whether x is allowed to denote the identity function and support if so #3577

@gwhitney

Description

@gwhitney

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

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions