Skip to content

add

Syntax

add(x, y)

Parameters

x
An expression that evaluates to a number or a list.
y
An expression that evaluates to a number or a list.

Returns

The result is a single value if both arguments are single-valued expressions; otherwise the result is a list.

Description

If x and y are single-valued expressions, the action returns the sum of the two given values (x + y).

If one the arguments is a single-valued expression and the other is a list-expression, then the action returns a list of values where each element is the sum of the single value parameter and the element with the same index in the list parameter.

If both arguments are lists, the action returns a list containing the sum of each pair of elements from the two list parameters.

This action is the prefix notation for the expression x + y.

If both arguments are list-expressions, a run-time error occurs if the lists have different lengths.

Examples

z = add(1, 2)  # z = 3
z = 1 + 2      # z = 3

my_list = list(1, 2, 3)
new_list = add(my_list, 4)  # new_list = list(5, 6, 7)
new_list = my_list + 4      # new_list = list(5, 6, 7)
new_list = 4 + my_list      # new_list = list(5, 6, 7)

new_list = my_list + my_list  # new_list = list(2, 4, 6)

See Also