[Python] curry?
Bob Miller
kbob at jogger-egg.com
Thu Oct 5 15:07:44 PDT 2006
Rob Hudson wrote:
> I think, in general, there's a concept about "curry" or "currying" that
> I'm not familiar with.
There's less to currying than meets the eye. Currying a function
means providing values for some of its arguments.
For example, if foo already exists:
def foo(a, b, c):
pass
Then I can write bar which curries foo so you only pass in b.
def bar(b):
return foo('aye', b, 'see')
It's a bit of a mystery to me why this concept deserves a name.
In Python, you'd be more likely to write foo with default args.
def foo(b, a='aye', c='see'):
pass
then you can call foo('bee') or foo('bea', 'eh?', 'si').
In languages that don't have default args, it's somewhat more useful.
It's also more useful in languages where function compositions are
more basic than in Python (i.e., Haskell).
--
Bob Miller K<bob>
kbob at jogger-egg.com
More information about the Python
mailing list