[Python-Dev] Re: PEP 309, function currying

Edward Loper edloper at gradient.cis.upenn.edu
Tue Feb 24 12:05:07 EST 2004


Peter Harris wrote:
>>* curry()
>>
>>* closure()
>>
>>* partial()
>>
>>* partial_apply()
>>
>>* delayed()
>>
>>* other ?

bind() and bindargs() seem pretty reasonable to me.  But if you don't 
like those, then how about fixargs() or fix_args()?  That gets across 
the message that we're generating a new function that fixes the values 
of a subset of the arguments.

Side note: I think that the following code will have unexpected behavior 
with the current implementations:

 >>> def f(x,y,z): return (x,y,z)
 >>> g = f.bind(y=3)
 >>> print g(1,2)
TypeError: f() got multiple values for keyword argument 'y'

(I would have expected this to return (1,3,2).)

Of course, there's not really any way around it without using 
inspection, and even then you can't really inspect argument lists for 
builtins.  But it might be worth noting in the docs the circumstances 
under which it's appropriate to bind w/ keyword args.

-Edward




More information about the Python-Dev mailing list