Function currying extension module
Carl Banks
imbosol-1045699014 at aerojockey.com
Wed Feb 19 19:05:34 EST 2003
Raymond Hettinger wrote:
>> Opinion, comments, suggestions on how to make it faster? It appears
>> that the bottleneck is allocating a tuple, which not much can be done
>> about.
>
> The tuple allocation can be avoided by re-using the
> same tuple over and over. For a safe, fast implementation look in
> CVS for the izip() function in the new itertools module.
I'll have a look.
> You are also losing a few cycles in the parsing of "OOOO" in
> PyObject_CallFunction. Instead, try PyObject_CallFunctionObjArgs.
I don't care much; it's in the init code.
> The use of the slot objects also adds a cost that is not in a pure
> lambda version. Here, you're paying a price for full generality.
> A simple curry (without keywords or positional control) would
> require much less code, be more readily learnable, and run faster:
>
>>>> add1 = curry(operator.add, 1)
>>>> add1(10)
> 11
Well, see the thing is, generality is what motivates me. I wanted
something akin to Function in Mathematica. A simple curry won't work
for something like this:
first = curry(operator.getitem, 1)
# wrong, unless curry was a right curry
Thanks for the advice,
--
CARL BANKS
More information about the Python-list
mailing list