summaryrefslogtreecommitdiff
path: root/ipl/procs/reduce.icn
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2013-01-27 23:51:56 +0000
committerIgor Pashev <pashev.igor@gmail.com>2013-01-27 23:51:56 +0000
commit6ab0c0f5bf14ed9c15370407b9ee7e0b4b089ae1 (patch)
tree926065cf45450116098db664e3c61dced9e1f21a /ipl/procs/reduce.icn
downloadicon-6ab0c0f5bf14ed9c15370407b9ee7e0b4b089ae1.tar.gz
Initial upstream version 9.4.3upstream/9.4.3
Diffstat (limited to 'ipl/procs/reduce.icn')
-rw-r--r--ipl/procs/reduce.icn34
1 files changed, 34 insertions, 0 deletions
diff --git a/ipl/procs/reduce.icn b/ipl/procs/reduce.icn
new file mode 100644
index 0000000..861ef38
--- /dev/null
+++ b/ipl/procs/reduce.icn
@@ -0,0 +1,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