up previous next
sum

the sum of the elements of a list

Syntax
sum(L: LIST): OBJECT
sum(L: LIST, InitVal: OBJECT): OBJECT

Description
This function returns the sum of the objects in the list L (together with InitVal , if specified). When writing a program, if the list L may be empty, you must specify InitVal .

Example
/**/  use R ::= QQ[x,y];
/**/  sum([3, x, y^2]);
y^2 +x +3

/**/  sum(1..40) = binomial(41,2);
true

/**/  sum(["c","oc","oa"]);
cocoa

/**/ sum([]);  -- gives 0 of type INT
0
/**/ sum([], "");  -- gives empty STRING

/**/ sum([], x);  -- gives type RINGELEM
x

See Also