string concatenation doc issue and questions
- Dominant language
- JavaScript
- Stars
- 15.1k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
The page https://mathjs.org/docs/datatypes/index.html includes the example `math.add('hello ', 'world')` with the expected return value `'hello world'` but this fails. It has the example `math.max('A', 'D', 'C')`, but this also fails.
Of the types listed on that page, only Boolean and String do not have their own page. Should String? I think so, because (a) strings are a common and important datatype, and (b) there are some subtleties with mathjs strings, as the first example shows. Should Boolean as well, just for the sake of uniformity/thoroughness?
The [doc page for concat](https://mathjs.org/docs/reference/functions/concat.html) does not mention string in the text, nor in the possible typings. It does show one string example. But strings are not Array | Matrix in the mathjs type system. So this documentation should be corrected as well.
And should we hack the doc page generation so that concat appears both in the Matrix and String section of the [function reference](https://mathjs.org/docs/reference/functions.html)? Are there any other Matrix methods that work for string as well?
Clearly `'a' + 'b'` used to work in the expression language. It's been removed for good reason, but `concat('a', 'b')` is a bit cumbersome. Should we introduce a (string and/or array/Matrix) concatenation operator (that would presumably coerce its operands to (strings and/or arrays/Matrices, as appropriate)? If so, what should the operator be? Possibilities that come to mind are:
* `++`, if one is willing to require `7 + +5` to have to have the space between the two plus symbols (I certainly would be, because it is super rare for unary + to be useful);
* `.+` by very rough analogy with `.*` and `./` -- it is _not_ elementwise addition, because _ordinary_ matrix addition already is elementwise, but it _is_ the "other sort of addition you might want to do" just like `.*` is the "other sort of multiplication you might want to do"; or
* `&&` because we are not using this for logical and, so it is open.
There may be other reasonable possibilities.
**To Reproduce**
`math.add('hello ', 'world')` --> Throws `Error: cannot convert 'hello ' to number`
`math.max('A', 'D', 'C')` --> Throws `Error: cannot convert 'D' to number`
Contributor guide
Assessment
This issue has not been assessed yet.