Concatenation versus addition

Tinderbox Icon

In Tinderbox, the plus symbol (+) is used both to concatenate (join) strings of text and to sum figures. Thus

$MyString = "My favourite colour is " + $FavouriteColour 

$MyNumber = 4 + 3 

Nothing untoward there, not least as the target data type (as implied here by the left side attribute name) helps Tinderbox guess the user's intent. But what about:

$MyString = "6" + 4 

Is it "64", 64, "10" or 10? As the target attribute is String-type, the result is a string. As one of the right side arguments is a string, then a concatenation is used. If both (all) arguments are numbers, then an addition occurs before being saved as a string:

$MyString = "6" + 4 gives "64"

$MyString = 6 + 4 gives "10"

$MyString = 6 + "4" gives "64"

$MyString = "6" + "4" gives "64"

In earlier versions of Tinderbox, there was no need to quote strings and Tinderbox guessed string/number by context. Since then, as the action code has got richer, it has become harder to divine the user's intent, thus the move to expecting text to be placed in double quotes. Incidentally it also makes it easier to indicate intent with regard to leading/trailing white space.

Thus, when using the '+' operator try to ensure Tinderbox isn't having to guess too hard as to the desired outcome.

Up: Actions & Rules
Previous: Using Export codes in Actions (deprecated)   

[Last updated: 14 Dec 2009, using v5.0]

Google search aTbRef for:  

Licensed under Creative Commons Attribution-Noncommercial-Share Alike 3.0 License
[See aTbRef CC licence Attribution/Waiver info info]

Creative Commons License

Made with Tinderbox