Partially evaluated functions

Nick Perkins nperkins7 at
Thu Jun 21 23:29:09 CEST 2001

I meant to repy on clp, but only sent email by accident.

Rainer is right.
His implementation of curry does avoid a certain class of problems,
namely, when you want to pass a kwd arg to the 'inner' function,
but the actual curry function 'grabs' the arg for itself if the
keyword matches any formal parameters to the curry function.
(eg. 'self', or 'func')
I am sorry, I did not understand at first.

Also, Alex has pointed out a flaw in the 'no kwd.copy() necessary' thing,
for curry implementations that give precedence to call-time kwd args.
The original cookbook version had it right to begin with.  Now I know why.

So, incorporating the elimination of named args,
and my preference for 'left-to-right' positional args,
and call-time precedence,
and the elegance of the functional version supplied by Alex,
I presently have:

def curry(*args, **create_time_kwds):
    func = args[0]
    create_time_args = args[1:]
    def curried_function(*call_time_args, **call_time_kwds):
        args = create_time_args + call_time_args
        kwds = create_time_kwds.copy()
        return func(*args, **kwds)
    return curried_function

It's a bit longer becuase I am trying to be very explicit about the

ps.  it would be nice if
dict1 + dict2
returned a new 'merged' dictionary..

More information about the Python-list mailing list