[Python-ideas] Syntax for defining parametric decorators

Devin Jeanpierre jeanpierreda at gmail.com
Mon Jul 9 01:47:07 CEST 2012


On Sun, Jul 8, 2012 at 7:13 PM, Mathias Panzenböck
<grosser.meister.morti at gmx.net> wrote:
> This would be a currified function. One could implement something like that
> like this:
>
> def curry(f):
>         for i in range(f.func_code.co_argcount-1):
>                 f = (lambda f: lambda *args: partial(f,*args))(f)
>         return f
>
> @curry
> def timesn(n,f,y):
>         return n * f(y)

But then how do you do:

def linearcomposition(m, c=0)(f)(x):
    return m * f(x) + c

Python isn't Haskell, so we can't really currify every argument and
expect things to work out, esp. because of variadic functions
(defaults or even *args and **kwargs).

-- Devin



More information about the Python-ideas mailing list