diff options
author | Guido van Rossum <guido@python.org> | 2006-08-22 00:21:25 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2006-08-22 00:21:25 (GMT) |
commit | 89da5d7c3d9cf5bfd4a374e23fd924bbffdeaf5c (patch) | |
tree | aef767c70a3b57c4128d44816e4e070d28fffb9d /Python/bltinmodule.c | |
parent | 6cefeb0e8156406ac3f99248f6a3d3cd1536ca23 (diff) | |
download | cpython-89da5d7c3d9cf5bfd4a374e23fd924bbffdeaf5c.zip cpython-89da5d7c3d9cf5bfd4a374e23fd924bbffdeaf5c.tar.gz cpython-89da5d7c3d9cf5bfd4a374e23fd924bbffdeaf5c.tar.bz2 |
Kill reduce(). A coproduction of John Reese, Jacques Frechet, and Alex M.
Diffstat (limited to 'Python/bltinmodule.c')
-rw-r--r-- | Python/bltinmodule.c | 75 |
1 files changed, 0 insertions, 75 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 9616394..16758d7 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -1598,80 +1598,6 @@ These are exactly the valid indices for a list of 4 elements."); 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 @@ static PyMethodDef builtin_methods[] = { {"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}, |