4 ms·
There’s also functools.partial as another option. incr = partial(add, 1) incr(3)
by memco 4y ago
There’s also functools.partial as another option.
incr = partial(add, 1)
incr(3)
- quietbritishjim 4y agoBoth you and the parent comment have mistook partial function application for currying. Partial function application: incr = partial(add, 1) # or def incr(x): return add(x, 1) z = incr(4) (Side note: parent comment made a classic mistake, you shouldn't use a lambda if you're just going to assign it to a local variable, you should use a nested function definition.) Currying is function that returns a function: def curried_add(x): def inner(y): return add(x, y) return inner z = curried_add(1)(4)
- Izkata 4y agoOn top of that I figured the article meant automatic currying.
- tantalor 4y agoNo, not going to do any of that.
- memco 4y agoIn my defense, I did not say partial is currying, just that it is an alternative to a lambda in Python. I agree with your points, and with Izkata that the more relevant nuance is not that Python cannot curry, but that it doesn't do currying as fluently as Haskell, which I think was GP's point about the article. The crux of the article seems to have very little support for the argument of the title that lambdas shouldn't be in Python, but instead only seeks to make clear that "we do not use lambda with the intention of using lambda calculus." It's strongest contribution is to suggest that inline anonymous functions would be a helpful addition to the addition for Python to be able to do lambda calculus.