I am trying to write a currying decorator in python, and I think I've got the general idea down, but still got some cases that aren't working right...
def curry(fun):
cache = []
numargs = fun.func_code.co_argcount
def new_fun(*args, **kwargs):
print args
print kwargs
cache.extend(list(args))
if len(cache) >= numargs: # easier to do it explicitly than with exceptions
temp = []
for _ in xrange(numargs):
temp.append(cache.pop())
fun(*temp)
return new_fun
@curry
def myfun(a,b):
print a,b
While for the following case this works fine:
myfun(5)
myfun(5)
For the following case it fails:
myfun(6)(7)
Any pointers on how to correctly do this would be greatly appreciated!
Thanks!
curry
? – Wes Apr 15 '12 at 15:38