diff Python/bltinmodule.c @ 39627:e86c0b29b4a2

Kill reduce(). A coproduction of John Reese, Jacques Frechet, and Alex M.
author Guido van Rossum <guido@python.org>
date Tue, 22 Aug 2006 00:21:25 +0000
parents 3674f20ac781
children 13d5e5f0e993
line wrap: on
line diff
--- a/Python/bltinmodule.c	Mon Aug 21 23:45:19 2006 +0000
+++ b/Python/bltinmodule.c	Tue Aug 22 00:21:25 2006 +0000
@@ -1598,80 +1598,6 @@
 
 
 static PyObject *
-builtin_reduce(PyObject *self, PyObject *args)
-{
-	PyObject *seq, *func, *result = NULL, *it;
-
-	if (!PyArg_UnpackTuple(args, "reduce", 2, 3, &func, &seq, &result))
-		return NULL;
-	if (result != NULL)
-		Py_INCREF(result);
-
-	it = PyObject_GetIter(seq);
-	if (it == NULL) {
-		PyErr_SetString(PyExc_TypeError,
-		    "reduce() arg 2 must support iteration");
-		Py_XDECREF(result);
-		return NULL;
-	}
-
-	if ((args = PyTuple_New(2)) == NULL)
-		goto Fail;
-
-	for (;;) {
-		PyObject *op2;
-
-		if (args->ob_refcnt > 1) {
-			Py_DECREF(args);
-			if ((args = PyTuple_New(2)) == NULL)
-				goto Fail;
-		}
-
-		op2 = PyIter_Next(it);
-		if (op2 == NULL) {
-			if (PyErr_Occurred())
-				goto Fail;
- 			break;
-		}
-
-		if (result == NULL)
-			result = op2;
-		else {
-			PyTuple_SetItem(args, 0, result);
-			PyTuple_SetItem(args, 1, op2);
-			if ((result = PyEval_CallObject(func, args)) == NULL)
-				goto Fail;
-		}
-	}
-
-	Py_DECREF(args);
-
-	if (result == NULL)
-		PyErr_SetString(PyExc_TypeError,
-			   "reduce() of empty sequence with no initial value");
-
-	Py_DECREF(it);
-	return result;
-
-Fail:
-	Py_XDECREF(args);
-	Py_XDECREF(result);
-	Py_DECREF(it);
-	return NULL;
-}
-
-PyDoc_STRVAR(reduce_doc,
-"reduce(function, sequence[, initial]) -> value\n\
-\n\
-Apply a function of two arguments cumulatively to the items of a sequence,\n\
-from left to right, so as to reduce the sequence to a single value.\n\
-For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates\n\
-((((1+2)+3)+4)+5).  If initial is present, it is placed before the items\n\
-of the sequence in the calculation, and serves as a default when the\n\
-sequence is empty.");
-
-
-static PyObject *
 builtin_reload(PyObject *self, PyObject *v)
 {
 	return PyImport_ReloadModule(v);
@@ -2071,7 +1997,6 @@
  	{"ord",		builtin_ord,        METH_O, ord_doc},
  	{"pow",		builtin_pow,        METH_VARARGS, pow_doc},
  	{"range",	builtin_range,      METH_VARARGS, range_doc},
- 	{"reduce",	builtin_reduce,     METH_VARARGS, reduce_doc},
  	{"reload",	builtin_reload,     METH_O, reload_doc},
  	{"repr",	builtin_repr,       METH_O, repr_doc},
  	{"round",	(PyCFunction)builtin_round,      METH_VARARGS | METH_KEYWORDS, round_doc},