reduce

func reduce(binop : Map, lst : List) -> Entity
  return Undefined when #lst = 0
  return lst(1) when #lst = 1
  return binop(reduce(binop, all_but_last(lst)), last(lst))

Inserts the given binary operator between the elements of the list and returns the value of the resulting epxression. The binary operator can be any function of two arguments, or one of the built-in binary operators. The latter have to be specified as a strings. For example:
  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.