currying at language level (was: Re: add_command)

holger krekel pyth at devel.trillke.net
Tue May 14 05:32:01 EDT 2002


<taken back to the the list, hope that's ok with you>

Paul Foley wrote:
> On Mon, 13 May 2002 10:49:55 +0200, holger krekel wrote:
> 
> > Alex Martelli wrote:
> >> You can also curry in Python 1.5.2 should you need to -- it's just
> >> a _little_ bit clunkier perhaps:
> >> 
> >> def curry(func, *args, **kwds):
> >> def curried(f=func, a=args, k=kwds):
> >> return apply(f, a, k)
> >> return curried
> 
> > Alex, what do you think about integrating the
> > currying-concept into python's syntax like so:
> 
> > def normalfunc(arg1,arg2,arg3): pass
> 
> > curryfunc = normalfunc(arg1, *, arg3)
> 
> Python already has it:
> 
>   curryfunc = lambda x: normalfunc(arg1, x, arg3)
> 
> now that Python has lexical scoping.

your are right and this obsoletes my suggestion mostly. 
Using lambdas seems cleaner than introducing new syntax.

And introducing a builtin like 'curry' (see alex post)
tends to be wordier and harder to read than your simple
solution. IMO the '*' syntax thing may make the intention
of prebinding arguments a bit more obvious than lambdas 
or a builtin but it's (probably) not worth thinking about.

regards,

    holger





More information about the Python-list mailing list