blob: 861ef38ad3d89e1cf349e5c20f77be56fbc7ea0a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
############################################################################
#
# File: reduce.icn
#
# Subject: Procedure to perform operation on list of arguments
#
# Author: Ralph E. Griswold
#
# Date: January 14, 1995
#
############################################################################
#
# This file is in the public domain.
#
############################################################################
#
# reduce(op, init, args[]) applies the binary operation op to all the
# values in args, using init as the initial value. For example,
#
# reduce("+", 1, args[])
#
# produces the sum of the values in args.
#
############################################################################
procedure reduce(op, init, args[])
op := proc(op, 2) | stop("*** invalid operator for reduce()")
every init := op(init, !args)
return init
end
|