reduce

ABSTRACT

Applies a binary operator repeatedly to a vector. We define the behavior recurisely. If the input vector is of zero length, then the seed value is returned. Otherwise, we first calculate the reduced value on the prefix of the input vector that contains all but the last element. Label that value x and the last element of v will be labelled y (the element we excluded in the recursive call). The returned value of the function is then the value of binary(x, y).

REMARK

Generally, I find the syntax of this function to be a bit clunky in Monocurl and in many cases it is generally easier to just write a for loop that does the same thing when necessary. The function is still provided in the standard library regardless.

PARAMETERS
vthe vector that will supply the argument y for the binary operator
seedthe seed that will be used to start the reduction process
binary(x,y)the binary operator
RETURN

the value calculated according to the process specified above

DECLARATION
func reduce(v, seed, binary(x, y))