The addition or "binary plus" operator + adds the value of the right operand to the value of the left operand and returns the resulting value.
This operator performs mathematical addition if both operands contain decimal or integer values. The result will be a decimal if either operand is a decimal value.
This operator performs string concatenation if the left-hand operand is a string. The result is the left operand followed by the right operand converted into a string. Some types permit string concatenation if only the right-hand operand is a string, but this must be explicitly supported by the type in question (for example, the integer type supports this for convenience and for compatibility with previous language versions).
This operator also comes in a positive or "unary plus" method variant. This method variant is differentiated by not accept a parameter. I.e. it does not accept the parameter which would normally represent the right-hand operand. Unary plus generally only applies to integers or decimals, although any type may implement this method if needed.
The + method to be called is always the one belonging to the left-hand operand. When creating a custom implementation of either the binary or unary plus operator, it is important to not modify either operand. The + operator should always return a newly created value.
Also provided is the stand-alone + method which can be accessed using the escape method operator. This permits addition operations to be passed as values and later invoked for whatever reason. This method eventually calls the + operator on the left-hand operand.
Often, the + method is only supported with a particular type of left-hand operand. If the + operator is not supported for the given left and right operand type combination, the standard "definition not found" failure will occur.
Note that directly calling the + operator method (e.g. 'hi'->+('bye')) is not permitted. However, it is permitted to access an object's + method using the escape method operator (e.g. 'hi'->\+).
Some container types (such as array and staticarray) use this operator to permit two containers to be "added" together, resulting in a new container consisting of all values from both operands.
left_parameter + right_parameter local(result = left_parameter + right_parameter) #result = left_parameter + right_parameter +value
This results in a new array containing all values from both operands.
array(1, 2, 3, 4, 5) + array(6, 7, 8, 9, 0)
array(1, 2, 3, 4, 5, 6, 7, 8, 9, 0)
local(op = \+) #op(5, 20)
25 Equivalent to 5 + 20
Please note that periodically LassoSoft will go through the notes and may incorporate information from them into the documentation. Any submission here gives LassoSoft a non-exclusive license and will be made available in various formats to the Lasso community.