Error Messages/40122
Example Error Message
- The + operator or Sum() function was used with a text value. Use the & operator or the JoinText() function instead if your intention is to concatenate text.
- In a future release, use of + or Sum for text concatenation will be disallowed entirely.
or
Description
Use the + operator for addition of numeric values. Do not use it to concatenate text values. If you want to concatenate text, use the &
operator. Similarly, you should use Sum to sum numeric values, not for concatenation. JoinText is used to concatenate cells of an array textually.
Many programming languages use + for text concatenation, for example "Hello" + "World" → "HelloWorld"
. Although common, this is a bad design choice, since addition is commutative (i.e., [math]\displaystyle{ a+b = b+a }[/math]) whereas text concatenation is not.
Use &
or JoinText:
"Hello" & "World" → "HelloWorld"
JoinText( ["Hello", "World"] ) → "HelloWorld"
Changing standards
For more than a decade, Analytica issued a warning when + was used for text concatenation, but concatenated the text if you ignored the warning. The warning also warned that eventually a future release of Analytica would stop supporting + for text concatenation.
Starting with Analytica 5.0, the result of x+y
when x or y is text shall be NAN, rather than the concatenation of text. There are number of motivations related to performance enhancement, both in 5.0 and in the future, that motivate this change. But, because this change does represent a break with backward compatibility, a preference option exists to preserve the older behavior in models created prior to Analytica 5.0. That legacy preference is the "x+y returns NAN for text" preference, which is OFF for legacy behavior.
However, if you turn off "x+y returns NAN for text" (it is off when a model created prior to 5.0 is loaded), then an error occurs when a + operator or Sum function is evaluated on a textual parameter and multithreading is on. This error may prevent some legacy models from successfully evaluating, since unlike when it was just a warning, you can't ignore an error. Legacy models running in release 5.0 thus have these options:
- Fix the model so that it uses the & operator or JoinText function for the text concatenation.
- If the error occurs with Sum, specify the optional «ignoreNonNumbers» parameter to Sum as true.
- Turn on the "x+y returns NAN for Text" preference.
- Turn off multithreaded evaluation (by setting MaxModelThreads to 1), or
Turning off multithreaded evaluation is the least desirable of these options, not just because you lose the overall performance boost, but also because it masks the use of a feature that is destined to be completely deprecated. It is better to solve the problem now.
There are cases where the error is somewhat spurious, occurring because Analytica evaluates certain things in fast array-level operations. For example, in the expression
it seems like this should be immune to the problem, even if x
contains a mixture of text and numbers. However, since the Then clause is evaluated in array fashion, the x+1
evaluates for every cell (at least when x
contains at least two numbers as well as non-numbers), so the error occurs. However, the result is never used, so setting the "x+y returns NAN for Text" preference is the perfect solution here.
If your legacy model really is trying to concatenate text using + or Sum then you should take the time to change it to use & and JoinText. Eventually this will be required.
Enable comment auto-refresher