reduce(f, [a b c]) = f(f(a, b), c)
reduce(f, [a b]) = f(a, b)
reduce(f, [a]) = a
reduce(f, []) = Undefined
reduce(`+', [1 2 3]) = 1 + 2 + 3 = 6 = sum([1 2 3])
reduce(`*' [1]) = 1 = prod([1])
reduce(`+' []) = Undefined /= sum([])
Note that reduce can be used to define concat, prod, sum and union:
concat(l) = reduce(`+', [`']+l)
prod(l) = reduce(`*', l)?0
sum(l) = reduce(`+', [0]+l)
union(l) = reduce(`+', [{}]+l)
And here a function to convert a list of numbers into a comma-delimited,
bracketted string: b(s, t) = s + `, ' + t
c(lst) = `('+reduce(b, fmap(mkstr, lst))?`'+`)'
Herman Venter
This is Slim documentation as snarfed on 27 May 1999 by dB.