Re: Python-Dev Digest, Vol 7, Issue 45

Edward Loper wrote:
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
Well, I'm coming to like partial(), because it's short enough, and relates to the term 'partial application'. I don't like verb-based names for this, because you are not doing an action so much as creating a thing. A noun would be splendid if an appropriate one could be found; failing that, an adjective will do, as it _implies_ a noun. So partial() evaluates as a 'partial' something, but bind() looks like it's binding something but not necessarily focusing attention on the fact that what we are making is an object. Peter Harris
participants (1)
-
Peter Harris