I am trying to run this snippet from http://www.ibm.com/developerworks/linux/library/l-prog3.html in python 2.6 runtime.
from functional import * taxcalc = lambda income,rate,deduct: (income-(deduct))*rate taxCurry = curry(taxcalc) taxCurry = taxCurry(50000) taxCurry = taxCurry(0.30) taxCurry = taxCurry(10000) print "Curried taxes due =",taxCurry print "Curried expression taxes due =", \ curry(taxcalc)(50000)(0.30)(10000)
Well, thatβs why I understand from http://www.python.org/dev/peps/pep-0309/ that the functionality is renamed to functools and curry to partial, but just doing the renaming does not help, I get an error message:
taxCurry = taxCurry(50000) TypeError: <lambda>() takes exactly 3 arguments (1 given)
The following works, but do I really need to change it so much?
from functools import partial taxcalc = lambda income,rate,deduct: (income-(deduct))*rate taxCurry = partial(taxcalc) taxCurry = partial(taxCurry, 50000) taxCurry = partial(taxCurry, 0.30) taxCurry = partial(taxCurry, 10000) print "Curried taxes due =", taxCurry() print "Curried expression taxes due =", \ taxcalc(50000, 0.30, 10000)
Is there a better way to keep the mechanics of the original example? After all, was the original example really currying or just a partial application? (according to http://www.uncarved.com/blog/not_currying.mrk )
thank you for your time
source share